VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 6645 ClientLeft = 165 ClientTop = 735 ClientWidth = 6975 LinkTopic = "Form1" ScaleHeight = 6645 ScaleWidth = 6975 StartUpPosition = 3 'Windows Default Begin VB.Frame Frame1 Height = 1215 Left = 1560 TabIndex = 5 Top = 240 Width = 1215 Begin VB.OptionButton optCheck Caption = "C&heck" Height = 255 Left = 120 TabIndex = 7 Top = 720 Width = 855 End Begin VB.OptionButton optDeposit Caption = "&Deposit" Height = 255 Left = 120 TabIndex = 6 Top = 240 Value = -1 'True Width = 975 End End Begin VB.CommandButton cmdCalculate Caption = "&Calculate" Height = 495 Left = 1560 TabIndex = 3 Top = 2040 Width = 1215 End Begin VB.TextBox txtAmount Height = 375 Left = 4440 TabIndex = 0 Top = 360 Width = 1095 End Begin VB.Label Label1 Caption = "Balance:" Height = 255 Left = 3120 TabIndex = 4 Top = 1080 Width = 1095 End Begin VB.Label Label2 Caption = "Enter Amount:" Height = 255 Left = 3120 TabIndex = 2 Top = 360 Width = 1215 End Begin VB.Label lblBalance Caption = "0" Height = 255 Left = 4560 TabIndex = 1 Top = 1080 Width = 615 End Begin VB.Menu mnuFile Caption = "&File" Begin VB.Menu mnuFileTransaction Caption = "T&ransaction" End Begin VB.Menu mnuFileSummary Caption = "&Summary" End Begin VB.Menu mnuFileExit Caption = "E&xit" End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False 'Ch 5 Demo Program #4 'Mr. Minich 'This program demonstrates the use of general function procedures and serves as a partial model to ' Programming Assignment #1. It does not include any input validation nor much control of the focus. ' The program's user interface is lacking as well. ' It also includes a menu and demonstrates how a command button's Click event procedure can call ' a menu command Click event procedure. It demonstrates good internal documentation where the inline ' comments are lined up vertically. Option Explicit 'Module-level variables Dim mintNumChecks As Integer ' number of cleared checks Dim mcurAmountChecks As Currency ' accumulated sum of cleared checks Dim mintNumDeposits As Integer ' number of deposits Dim mcurAmountDeposits As Currency ' accumulated sum of deposits Private Sub mnuFileTransaction_Click() If optDeposit Then lblBalance = curDeposit(lblBalance, txtAmount) ' calling curDeposit (a function procedure) ElseIf optCheck Then lblBalance = curCheck(lblBalance, txtAmount) ' calling curCheck End If 'Warning: It is not necessarily a good idea to send a label's Caption property and a text box's ' Text property as arguments to a function that is expecting numeric values. That is, I ' probably should have used the Val function to be sure that VB would handle them as numbers ' and not strings but "what the heck", you only live once. txtAmount = "" ' clearing text box for next entry txtAmount.SetFocus ' setting focus back to the text box for next entry End Sub Private Function curDeposit(curBalance As Currency, sngAmount As Single) As Currency mintNumDeposits = mintNumDeposits + 1 ' incrementing number of deposits mcurAmountDeposits = mcurAmountDeposits + sngAmount ' updating total amount of deposits curDeposit = curBalance + sngAmount ' adding the deposit End Function Private Function curCheck(curBalance As Currency, sngAmount As Single) As Currency mintNumChecks = mintNumChecks + 1 ' incrementing number of checks mcurAmountChecks = mcurAmountChecks + sngAmount ' updating total amount of checks curCheck = curBalance - sngAmount ' debiting the check End Function Private Sub mnuFileSummary_Click() MsgBox "Number of Deposits: " & mintNumDeposits & vbCrLf & _ "Amount of Deposits: " & mcurAmountDeposits & vbCrLf & _ "Number of Checks: " & mintNumChecks & vbCrLf & _ "Amount of Checks: " & mcurAmountChecks, vbOKOnly, "Summary" End Sub Private Sub cmdCalculate_Click() Call mnuFileTransaction_Click ' calling the Transaction menu command End Sub Private Sub mnuFileExit_Click() End ' exiting the program End Sub