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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

EXAMPLE 4<br />

The following program uses a second form as a dialog box to total the different sources of income. Initially,<br />

only frmIncome is visible. The user types in his or her name <strong>and</strong> then either can type in the income<br />

or click on the comm<strong>and</strong> button for assistance in totaling the different sources of income. Clicking on the<br />

comm<strong>and</strong> button from frmIncome causes frmSources to appear <strong>and</strong> be active. The user fills in the three<br />

text boxes <strong>and</strong> then clicks on the comm<strong>and</strong> button to have the amounts totaled <strong>and</strong> displayed in the income<br />

text box of the first form.<br />

Private Sub cmdShowTot_Click()<br />

frmSources.Show vbModal<br />

End Sub<br />

Object Property Setting<br />

frmIncome Caption Income<br />

lblName Caption Name<br />

txtName Text (blank)<br />

lblTotal Caption Total Income<br />

txtTotal Text (blank)<br />

cmdShowTot Caption Determine Total Income<br />

Object Property Setting<br />

frmSources Caption Sources of Income<br />

BorderStyle 3 – Fixed Dialog<br />

lblWages Caption Wages<br />

txtWages Text (blank)<br />

lblInterest Caption Interest Income<br />

txtInterest Text (blank)<br />

lblDividend Caption Dividend Income<br />

txtDividend Text (blank)<br />

cmdCompute Caption Compute Total Income<br />

Private Sub cmdCompute_Click()<br />

Dim sum As Single<br />

sum = Val(txtWages.Text) + Val(txtInterest.Text) + Val(txtDividend.Text)<br />

frmIncome.txtTotal.Text = FormatCurrency(Str(sum))<br />

frmSources.Hide<br />

End Sub<br />

[Run, enter name, click the comm<strong>and</strong> button, <strong>and</strong> fill in the sources of income.]<br />

All variables declared <strong>and</strong> general procedures created in the (General) object of a form<br />

are local to that form; that is, they are not available to any other form. Such variables <strong>and</strong><br />

procedures are said to be of form level. However, you can declare global variables <strong>and</strong> pro-

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

Saved successfully!

Ooh no, something went wrong!