Info

Picture

apples.gif (located on the CD)

All of the code required to build the Fruit Stand program is shown here.

Option Compare Database Option Explicit

' declare module level variable and constants

Dim dRunningTotal As Double

Const TAXRATE = 0.07

Const dPricePerApple = 0.1

Const dPricePerOrange = 0.2

Const dPricePerBanana = 0.3

Private Sub cmdCalculateTotals_Click() ' declare procedure-level variables Dim dSubTotal As Double

Dim dTotal As Double Dim dTax As Double

' calculate and apply sub total dSubTotal = (dPricePerApple * Val(Me.txtApples.Value)) + _ (dPricePerOrange * Val(Me.txtOranges.Value)) + _ (dPricePerBanana * Val(txtBananas.Value))

Me.lblSubTotal.Caption = "$" & dSubTotal

' calculate and apply tax dTax = (TAXRATE * dSubTotal) Me.lblTax.Caption = "$" & dTax

' calculate and apply total cost dTotal = dTax + dSubTotal Me.lblTotal.Caption = "$" & dTotal

' build and apply runnning total using module-level variable dRunningTotal = dRunningTotal + dTotal Me.lblRunningTotal.Caption = "$" & dRunningTotal End Sub

Private Sub cmdExit_Click()

DoCmd.Quit ' terminates the application End Sub

Private Sub cmdResetFields_Click() ' reset application fields Me.txtApples.Value = "0" Me.txtOranges.Value = "0" Me.txtBananas.Value = "0" Me.lblSubTotal.Caption = "$0.00" Me.lblTax.Caption = "$0.00" Me.lblTotal.Caption = "$0.00" End Sub

Private Sub cmdResetRunningTotal_Click()

' reset running total variable and application field dRunningTotal = 0

Me.lblRunningTotal.Caption = "$0.00" End Sub

Private Sub Form_Load()

' set focus to first text box Me.txtApples.SetFocus

'set default quantities when the form first loads Me.txtApples.Value = 0 Me.txtBananas.Value = 0 Me.txtOranges.Value = 0 End Sub

0 0

Post a comment