home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
- Begin VB.Form frmSprdSht
- Caption = "Spreadsheet"
- ClientHeight = 1905
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 3450
- LinkTopic = "Form1"
- ScaleHeight = 1905
- ScaleWidth = 3450
- StartUpPosition = 3 'Windows Default
- Begin MSFlexGridLib.MSFlexGrid msgSprdsht
- Height = 735
- Left = 120
- TabIndex = 3
- Top = 1080
- Width = 2175
- _ExtentX = 3836
- _ExtentY = 1296
- _Version = 393216
- FixedRows = 0
- FixedCols = 0
- ScrollBars = 0
- End
- Begin VB.CommandButton cmdQuit
- Caption = "Quit"
- Height = 375
- Left = 2640
- TabIndex = 2
- Top = 240
- Width = 735
- End
- Begin VB.CommandButton cmdCols
- Caption = "Columns"
- Height = 375
- Left = 1680
- TabIndex = 1
- Top = 240
- Width = 855
- End
- Begin VB.CommandButton cmdRows
- Caption = "Rows"
- Height = 375
- Left = 720
- TabIndex = 0
- Top = 240
- Width = 855
- End
- Begin VB.Label lblMsg
- Caption = "Click on a cell to change its value"
- Height = 375
- Left = 120
- TabIndex = 5
- Top = 720
- Width = 5535
- End
- Begin VB.Label lblAdjust
- Caption = "Adjust"
- Height = 255
- Left = 120
- TabIndex = 4
- Top = 360
- Width = 495
- End
- Attribute VB_Name = "frmSprdSht"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim numRows As Integer 'number of rows
- Dim numCols As Integer 'number of columns
- Private Sub cmdCols_Click()
- Dim temp As String
- 'Adjust number of columns in the spreadsheet
- temp = InputBox("Enter new number of columns (2-7):")
- If (Val(temp) >= 2) And (Val(temp) <= 7) Then
- numCols = Val(temp)
- Call SetUpGrid
- Call ShowValues
- Call ShowTotals
- End If
- End Sub
- Private Sub cmdQuit_Click()
- End
- End Sub
- Private Sub cmdRows_Click()
- Dim temp As String
- 'Adjust the number of rows in the spreadsheet
- temp = InputBox("Enter new number of rows (4-24):")
- If (Val(temp) >= 4) And (Val(temp) <= 24) Then
- numRows = Val(temp)
- Call SetUpGrid
- Call ShowValues
- Call ShowTotals
- End If
- End Sub
- Private Sub Form_Load()
- 'Set default number of rows and columns
- numRows = 8 'row 0 is for headings, last 2 rows are for totals
- numCols = 2 'column 0 is for category names
- Call SetUpGrid
- Call ShowValues
- Call ShowTotals
- End Sub
- Private Sub msgSprdSht_Click()
- Dim temp As String, message As String
- 'Obtain new value for cell if it is not in the "Total" row
- If msgSprdsht.Row < numRows - 2 Then
- message = "Enter new value for the row"
- message = message & Str(msgSprdsht.Row + 1) & " column"
- message = message & Str(msgSprdsht.Col + 1) & " cell:"
- temp = InputBox(message, , msgSprdsht.Text) 'Propose old value as default
- If msgSprdsht.Col = 0 Then
- msgSprdsht.Text = temp
- ElseIf msgSprdsht.Row = 0 Then
- msgSprdsht.Text = temp
- Else
- msgSprdsht.Text = FormatNumber(Val(temp), , , , vbFalse)
- Call ShowTotals
- End If
- End If
- End Sub
- Private Sub SetUpGrid()
- Dim colNum As Integer
- 'Set up grid
- msgSprdsht.Col = 0
- msgSprdsht.Row = msgSprdsht.Rows - 1
- msgSprdsht.Text = "" 'erase "Total" in case increasing rows
- msgSprdsht.Rows = numRows
- msgSprdsht.Cols = numCols
- 'Set column widths; right-justify columns with numeric data
- msgSprdsht.ColWidth(0) = 2000 'space for category names
- msgSprdsht.ColAlignment(0) = 1 'show data left-justified
- For colNum = 1 To numCols - 1
- msgSprdsht.ColWidth(colNum) = 1200 'space for dollar amounts
- msgSprdsht.ColAlignment(colNum) = 7 'show data right-justified
- Next colNum
- 'Set overall grid size to minimum needed for the data
- msgSprdsht.Width = 2000 + (numCols - 1) * 1200 + 15 * (numCols + 1) + 8
- msgSprdsht.Height = numRows * msgSprdsht.RowHeight(0) + 15 * (numRows + 1) + 8
- 'Adjust form to accommodate grid and other controls
- frmSprdSht.Width = msgSprdsht.Left + msgSprdsht.Width + 200
- frmSprdSht.Height = msgSprdsht.Top + msgSprdsht.Height + 500
- frmSprdSht.Top = 0
- frmSprdSht.Left = 0
- End Sub
- Private Sub ShowTotals()
- Dim colNum As Integer, rowNum As Integer, total As Single
- 'Compute and display total of each numeric column
- msgSprdsht.Row = numRows - 1
- msgSprdsht.Col = 0
- msgSprdsht.Text = "Total"
- For colNum = 1 To numCols - 1
- total = 0
- For rowNum = 1 To numRows - 3
- msgSprdsht.Row = rowNum
- msgSprdsht.Col = colNum
- total = total + Val(msgSprdsht.Text)
- Next rowNum
- msgSprdsht.Row = numRows - 2
- msgSprdsht.Text = "----------------"
- msgSprdsht.Row = numRows - 1
- msgSprdsht.Text = FormatCurrency(total)
- Next colNum
- End Sub
- Private Sub ShowValues()
- Dim rowNum As Integer, colNum As Integer
- 'Refresh values displayed in cells
- For rowNum = 1 To numRows - 1
- For colNum = 1 To numCols - 1
- msgSprdsht.Row = rowNum
- msgSprdsht.Col = colNum
- msgSprdsht.Text = FormatNumber(Val(msgSprdsht.Text))
- Next colNum
- Next rowNum
- End Sub
-