' Mr. Minich ' Ch. 3 Demo Program #5 ' September 26, 2000 ' Purpose - to illustrate the use of a command button's Click event
' As you can probably see by examining the code below, this form requires the ' following objects to be placed on the form (with the correct Name properties):
' lblPromptMessage, lblOutputMessage, txtPrice, cmdClick, & cmdExit Option Explicit Private Sub Form_Activate() ' displays appropriate messages lblPromptMessage.Caption = "Enter a price:" ' displaying input prompt message txtPrice.Text = "" ' clearing the text box lblOutputMessage.Caption = "" ' clearing the label cmdClick.Caption = "Compute" ' setting Caption of command button cmdExit.Caption = "Exit" ' setting Caption of exit command button End Sub Private Sub cmdClick_Click() ' computes the total price including tax Dim sngPrice As Single ' price inputted by user Dim sngPriceWithTax As Single ' price including tax Const sngPA_SALES_TAX As Single = 0.06 ' PA state sales tax of 6% sngPrice = Val(txtPrice.Text) ' must change string into numeric value sngPriceWithTax = sngPrice + sngPrice * sngPA_SALES_TAX ' computing total price lblOutputMessage.Caption = "The total price is $" & sngPriceWithTax ' The & is the concatenation operator. It causes the string literal ' ...The total price is $... to neatly display concatenated next to the ' value of the variable sngPriceWithTax End Sub Private Sub cmdExit_Click() ' exits the program (form and project) Unload Me ' unloading the form End ' ending the project End Sub