19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

232 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

TABLE 7.2<br />

Tasks <strong>and</strong> Their Procedures<br />

Task Procedure<br />

1. Set up data file <strong>and</strong> form Form_Load<br />

1.1 Create data file CreateDataFile<br />

1.2 Read data file ReadDataFile<br />

1.3 Set up check SetupCheck<br />

1.4 Initialize text fields InitializeFields<br />

2. Record check or deposit slip cmdRecord_Click<br />

2.1 Verify that required data are given AllDataGiven<br />

2.2 Initialize text fields InitializeFields<br />

3. Toggle between check & deposit slip cmdMode_Click<br />

3.1 Set up check SetupCheck<br />

3.2 Set up deposit slip SetupDeposit<br />

3.3 Initialize text fields InitializeFields<br />

4. Print summary of transaction cmdPrint_Click<br />

5. Quit cmdQuit_Click<br />

Let’s examine each event procedure.<br />

1. Form_Load first looks to see if the file CHKBOOK.TXT has been created.<br />

The function Dir returns “CHKBOOK.TXT” if the file exists <strong>and</strong> otherwise<br />

returns the empty string. If CHKBOOK.TXT does not exist, the routine CreateDataFile<br />

is called. CreateDataFile prompts the user for the name to appear<br />

on the checks <strong>and</strong> deposit slips, the starting balance, <strong>and</strong> the numbers of the<br />

first check <strong>and</strong> deposit slip, <strong>and</strong> then writes these items to the data file. If CHK-<br />

BOOK.TXT does exist, the routine ReadDataFile is called to read through the<br />

entire file to determine all information needed to proceed. The event procedure<br />

calls SetupCheck to set the transaction type to Check <strong>and</strong> set the appropriate<br />

captions <strong>and</strong> background colors for a check. The event procedure then calls InitializeFields,<br />

which initializes all the text boxes.<br />

In the first assignment statement of the procedure, the drive is specified as the<br />

A drive. Therefore, the data file will be written to <strong>and</strong> read from a diskette on<br />

the A drive. Feel free to change the letter A to whatever drive you prefer. You<br />

may even want to specify an entire path.<br />

2. cmdRecord_Click first confirms that the required fields contain entries. This<br />

is accomplished by calling the function AllDataGiven. If the value returned is<br />

True, then cmdRecord_Click opens the data file for output as Append, sends<br />

eight pieces of data to the file, <strong>and</strong> then closes the file. When AllDataGiven<br />

returns False, the function itself pops up a message box to tell the user where<br />

information is needed. The user must type in the information <strong>and</strong> then press the<br />

Record button again.<br />

3. cmdMode_Click toggles back <strong>and</strong> forth from a check to a deposit slip. It calls<br />

SetupCheck, or its analog SetupDeposit, <strong>and</strong> then calls InitializeFields.<br />

4. cmdPrint_Click prints out a complete history of all transactions, as shown in<br />

Figure 7-6.<br />

5. cmdQuit_Click ends the program.<br />

Dim fileName As String ‘Name of data file<br />

Dim nameOnChk As String ‘Name to appear on checks<br />

Dim lastCkNum As Integer ‘Number of last check written<br />

Dim lastDpNum As Integer ‘Number of last deposit slip processed<br />

Dim curBal As Single ‘Current balance in account<br />

Dim transType As String ‘Type of transaction, check or deposit<br />

Private Function AllDataGiven() As Boolean

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!