home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / componen / vsflex / demo / mrgout.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-07  |  9.1 KB  |  310 lines

  1. VERSION 2.00
  2. Begin Form fTotals 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "FlexTotals"
  6.    ClientHeight    =   6030
  7.    ClientLeft      =   900
  8.    ClientTop       =   900
  9.    ClientWidth     =   6270
  10.    Height          =   6435
  11.    Left            =   840
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   6030
  14.    ScaleWidth      =   6270
  15.    Top             =   555
  16.    Width           =   6390
  17.    Begin CheckBox Check1 
  18.       BackColor       =   &H00C0C0C0&
  19.       Caption         =   "Only Subtotals"
  20.       FontBold        =   0   'False
  21.       FontItalic      =   0   'False
  22.       FontName        =   "MS Sans Serif"
  23.       FontSize        =   8.25
  24.       FontStrikethru  =   0   'False
  25.       FontUnderline   =   0   'False
  26.       ForeColor       =   &H00000000&
  27.       Height          =   210
  28.       Left            =   3405
  29.       TabIndex        =   3
  30.       Top             =   690
  31.       Width           =   1395
  32.    End
  33.    Begin CommandButton Command1 
  34.       BackColor       =   &H00C0C0C0&
  35.       Caption         =   "Rollups"
  36.       FontBold        =   0   'False
  37.       FontItalic      =   0   'False
  38.       FontName        =   "MS Sans Serif"
  39.       FontSize        =   8.25
  40.       FontStrikethru  =   0   'False
  41.       FontUnderline   =   0   'False
  42.       Height          =   345
  43.       Left            =   4935
  44.       TabIndex        =   2
  45.       Top             =   585
  46.       Width           =   990
  47.    End
  48.    Begin vsFlexArray fa 
  49.       BackColor       =   &H00FFFFFF&
  50.       BackColorFixed  =   &H00800000&
  51.       Cols            =   4
  52.       ConvInfo        =   MRGOUT.FRX:0000
  53.       DragIcon        =   MRGOUT.FRX:000B
  54.       FixedCols       =   0
  55.       FocusRect       =   0  'None
  56.       FontBold        =   -1  'True
  57.       FontItalic      =   0   'False
  58.       FontName        =   "Arial"
  59.       FontSize        =   9.75
  60.       FontStrikethru  =   0   'False
  61.       FontUnderline   =   0   'False
  62.       ForeColor       =   &H00000000&
  63.       ForeColorFixed  =   &H00FFFFFF&
  64.       FormatString    =   "^Region           |^Product       |^Employee    |>Sales            "
  65.       Height          =   4905
  66.       HighLight       =   0  'Never
  67.       Left            =   270
  68.       MergeCells      =   2  'Restrict Rows
  69.       ScrollTrack     =   -1  'True
  70.       TabIndex        =   0
  71.       Top             =   1050
  72.       Width           =   5760
  73.    End
  74.    Begin Label Label1 
  75.       BackColor       =   &H00000000&
  76.       BackStyle       =   0  'Transparent
  77.       Caption         =   "Drag headings over other columns to reorganize the summary sheet. You can show sales TOTALS by region, product, or employee."
  78.       FontBold        =   -1  'True
  79.       FontItalic      =   0   'False
  80.       FontName        =   "Arial"
  81.       FontSize        =   9.75
  82.       FontStrikethru  =   0   'False
  83.       FontUnderline   =   0   'False
  84.       ForeColor       =   &H00000000&
  85.       Height          =   915
  86.       Left            =   240
  87.       TabIndex        =   1
  88.       Top             =   75
  89.       Width           =   5760
  90.    End
  91. Option Explicit
  92. Sub Check1_Click ()
  93.    Dim i%
  94.    For i = 1 To fa.Rows - 1
  95.       If Not fa.MergeRow(i) Then fa.RowHeight(i) = check1 - 1
  96.    Next i
  97. End Sub
  98. Sub Command1_Click ()
  99.    MsgBox "Double-click on the yellow cells to collapse or expand detailed information"
  100. End Sub
  101. Sub DoCalculateTotals ()
  102.     '----------------------------------------------------------------
  103.     ' Loop thru all the cells and calculate totals and subtotals
  104.     '
  105.     ' SaveGroupingKeys
  106.     ' Do
  107.     '    ForAllLevels
  108.     '       if SameCategory then
  109.     '          AddTotals
  110.     '       Else
  111.     '          PrintTotals
  112.     '          Totals = 0
  113.     '          SaveSortingKeys
  114.     '       endif
  115.     ' Loop
  116.     Dim i%, j%, k%, h%
  117.     Dim s$(), tot()
  118.     Dim TotLevels%, TotOnColumn%
  119.     TotLevels = 2
  120.     TotOnColumn = 3
  121.     ReDim tot(TotLevels), s(TotLevels)
  122.     ' save first grouping keys
  123.     i = 1
  124.     For k = 0 To TotLevels - 1
  125.       s(k) = fa.TextArray(fai(1, k))
  126.     Next
  127.     Do
  128.         For h = 0 To TotLevels - 1
  129.            If s(h) = fa.TextArray(fai(i, h)) Then
  130.                tot(h) = tot(h) + Val(fa.TextArray(fai(i, TotOnColumn)))
  131.            Else
  132.                ' print totals
  133.                For k = TotLevels - 1 To h Step -1
  134.                   DoSubTotals k, s(k), tot(), i - (k - 1)
  135.                Next
  136.                i = i + TotLevels - h
  137.                ' reset totals
  138.                For k = h + 1 To TotLevels - 1
  139.                   tot(k) = 0
  140.                Next
  141.                For k = 0 To h
  142.                   tot(h) = fa.TextArray(fai(i, TotOnColumn))
  143.                Next
  144.                ' save new category index
  145.                For k = 0 To TotLevels - 1
  146.                  s(k) = fa.TextArray(fai(i, k))
  147.                Next
  148.            End If
  149.         Next h
  150.         
  151.         i = i + 1
  152.         If i >= fa.Rows Then
  153.             For k = TotLevels - 1 To 0 Step -1
  154.                   DoSubTotals k, s(k), tot(), i - (k - 1)
  155.             Next
  156.             Exit Do
  157.         End If
  158.     Loop
  159.     fa.MergeCells = 2
  160. End Sub
  161. Sub DoFillData ()
  162.     Dim i%
  163.     Dim sreg$, sprod$, semp$, ssale$
  164.     For i = fa.FixedRows To fa.Rows - 1
  165.       sreg = Region()
  166.       sprod = Product()
  167.       semp = Employee()
  168.       ssale = Sales()
  169.       fa.TextArray(fai(i, 0)) = sreg
  170.       fa.TextArray(fai(i, 1)) = sprod
  171.       fa.TextArray(fai(i, 2)) = semp
  172.       fa.TextArray(fai(i, 3)) = ssale
  173.     Next
  174. End Sub
  175. Sub DoRemoveTotals ()
  176.    Dim i%
  177.     '-------------------------------------------------
  178.     ' remove old totals
  179.     i = 1
  180.     While i < fa.Rows
  181.         fa.RowHeight(i) = -1
  182.         If fa.MergeRow(i) Then
  183.             fa.RemoveItem i
  184.         Else
  185.             i = i + 1
  186.         End If
  187.     Wend
  188. End Sub
  189. Sub DoSort ()
  190.     DoRemoveTotals
  191.     ' sort
  192.     fa.Col = 0
  193.     fa.ColSel = fa.Cols - 1
  194.     fa.Sort = 1
  195.     DoCalculateTotals
  196. End Sub
  197. Sub DoSubTotals (Level%, s$, tot(), i%)
  198.     Dim itm$, t$, k%
  199.     t = Chr(9)
  200.     Select Case Level
  201.       Case 1   ' Second Column Totals
  202.          itm = fa.TextArray(fai(i - 1, 0)) + t
  203.          For k = Level To fa.Cols - 2
  204.             itm = itm + s & " Total " & t
  205.          Next k
  206.          itm = itm + Format(tot(1), "#,##0.00")
  207.          
  208.          fa.AddItem itm, i
  209.          fa.MergeRow(i) = True
  210.          
  211.          ' change visual attributes
  212.          fa.Row = i
  213.          fa.Col = 1
  214.          fa.ColSel = 3
  215.          fa.CellBackColor = &H80FFFF    ' yellow
  216.          fa.CellFontBold = True
  217.       Case 0
  218.          itm = s + " Total"
  219.          itm = itm + t + itm + t + itm + t + Format(tot(0), "#,##0.00")
  220.          
  221.          fa.AddItem itm, i
  222.          fa.MergeRow(i) = True
  223.          
  224.          fa.Row = i
  225.          fa.Col = 0
  226.          fa.ColSel = 3
  227.          fa.CellBackColor = 1
  228.          fa.CellForeColor = RGB(255, 255, 255)
  229.          fa.CellFontBold = True
  230.     End Select
  231.        
  232. End Sub
  233. Function Employee () As String
  234.     Select Case (Rnd * 1000) Mod 3
  235.         Case 0: Employee = "Mary"
  236.         Case 1: Employee = "Sarah"
  237.         Case Else: Employee = "Paula"
  238.     End Select
  239. End Function
  240. Sub fa_DblClick ()
  241.     Dim r%
  242.     ' find totals row
  243.     r = fa.MouseRow
  244.     If r = 0 Then Exit Sub
  245.     If Not fa.MergeRow(r) Then Exit Sub
  246.     While Not fa.MergeRow(r)
  247.         r = r - 1
  248.     Wend
  249.     ' expand or contract?
  250.     r = r - 1
  251.     If fa.RowHeight(r) = 0 Then
  252.         Do While Not fa.MergeRow(r)
  253.             fa.RowHeight(r) = -1
  254.             r = r - 1
  255.             If r = 0 Then Exit Do
  256.         Loop
  257.     Else
  258.         Do While Not fa.MergeRow(r)
  259.             fa.RowHeight(r) = 0
  260.             r = r - 1
  261.             If r = 0 Then Exit Do
  262.         Loop
  263.     End If
  264. End Sub
  265. Sub fa_DragDrop (Source As Control, X As Single, Y As Single)
  266.     If fa.Tag = "" Then Exit Sub
  267.     If fa.Tag = fa.MouseCol Then Exit Sub
  268.     If fa.MouseCol = 3 Then Exit Sub
  269.     fa.Redraw = False
  270.     fa.ColPosition(Val(fa.Tag)) = fa.MouseCol
  271.     DoSort
  272.     fa.Redraw = True
  273. End Sub
  274. Sub fa_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  275.     fa.Tag = ""
  276.     If fa.MouseRow <> 0 Or fa.MouseCol = 3 Then Exit Sub
  277.     fa.Tag = Str(fa.MouseCol)
  278.     fa.Drag 1
  279. End Sub
  280. Function fai (r%, c%) As Integer
  281.     fai = c + fa.Cols * r
  282. End Function
  283. Sub Form_Load ()
  284.     DoFillData
  285.     fa.MergeCol(0) = True
  286.     fa.MergeCol(1) = True
  287.     fa.MergeCol(2) = True
  288.     fa.FillStyle = 1
  289.     DoSort
  290.     check1 = 0
  291. End Sub
  292. Function Product () As String
  293.     Select Case (Rnd * 1000) Mod 4
  294.         Case 0: Product = "Wahoos"
  295.         Case 1: Product = "Foobars"
  296.         Case Else: Product = "Applets"
  297.     End Select
  298. End Function
  299. Function Region () As String
  300.     Select Case (Rnd * 1000) Mod 4
  301.         Case 0: Region = "North"
  302.         Case 1: Region = "South"
  303.         Case 2: Region = "West"
  304.         Case Else: Region = "East"
  305.     End Select
  306. End Function
  307. Function Sales () As String
  308.     Sales = Format(Rnd * 10000, "#.00")
  309. End Function
  310.