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.

clicks on the square to toggle between the unchecked <strong>and</strong> checked states. So doing also triggers<br />

the Click event.<br />

EXAMPLE 1<br />

The following program allows an employee to compute the monthly cost of various benefit packages.<br />

Private Sub chkDrugs_Click()<br />

Call Tally<br />

End Sub<br />

Private Sub chkDental_Click()<br />

Call Tally<br />

End Sub<br />

Private Sub chkVision_Click()<br />

Call Tally<br />

End Sub<br />

Private Sub chkMedical_Click()<br />

Call Tally<br />

End Sub<br />

Private Sub Tally()<br />

Dim sum As Single<br />

If chkDrugs.Value = 1 Then<br />

sum = sum + 12.51 End If<br />

If chkDental.Value = 1 Then<br />

sum = sum + 9.68<br />

End If<br />

If chkVision.Value = 1 Then<br />

sum = sum + 1.5<br />

End If<br />

If chkMedical.Value = 1 Then<br />

sum = sum + 25.25<br />

End If<br />

lblAmount.Caption = FormatCurrency(sum)<br />

End Sub<br />

[Run <strong>and</strong> then click on the desired options.]<br />

Object Property Setting<br />

Nine Elementary Controls 295<br />

frmBenefits Caption Benefits Menu<br />

chkDrugs Caption Prescription Drug Plan<br />

($12.51)<br />

Value 0 – Unchecked<br />

chkDental Caption Dental Plan ($9.68)<br />

Value 0 – Unchecked<br />

chkVision Caption Vision Plan ($1.50)<br />

Value 0 – Unchecked<br />

chkMedical Caption Medical Plan ($25.25)<br />

Value 0 – Unchecked<br />

lblTotal Caption Total monthly payment:<br />

lblAmount Caption $0.00

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

Saved successfully!

Ooh no, something went wrong!