Link to home
Start Free TrialLog in
Avatar of oteskl
oteskl

asked on

VB 6.0 question

Hello,
I'm working on a programming assignment and I am stuck.  My code is patsed below.   I can't figure out how to retain the lblSubtotal, lblTax,and  lblTotal values from previous orders to add up the subtotal, tax, and total for the next order.

Any help will greatly be appreciated.

Thanks.

Code Below:

Sub Main()
'frmSplash.Show vbModeless
'Load Main
End Sub

Private Sub cmdCalculate_Click()
    Dim Subtotal As Single
    Dim Tax As Single
    Dim TotalDue As Single
    Dim previous As Single
    If optCappuccino.Value And chkTax.Value = 1 Then
        lblItemAmount = FormatCurrency(2 * txtQuantity)
        Call SubtotalSectionTax
        Subtotal = Subtotal + lblItemAmount
    ElseIf optCappuccino.Value Then
        lblItemAmount = FormatCurrency(2 * txtQuantity)
        Call SubtotalSectionNoTax
    End If

    If optEspresso.Value And chkTax.Value = 1 Then
        lblItemAmount = FormatCurrency(2.25 * txtQuantity)
        Call SubtotalSectionTax
           
    ElseIf optEspresso.Value Then
        lblItemAmount = FormatCurrency(2.25 * txtQuantity)
        Call SubtotalSectionNoTax
    End If

    If optLatte.Value And chkTax.Value = 1 Then
        lblItemAmount = FormatCurrency(1.75 * txtQuantity)
        Call SubtotalSectionTax
    ElseIf optLatte.Value Then
        lblItemAmount = FormatCurrency(1.75 * txtQuantity)
        Call SubtotalSectionNoTax
    End If
   
    If optIcedLatte.Value And chkTax.Value = 1 Then
        lblItemAmount = FormatCurrency(2.5 * txtQuantity)
        Call SubtotalSectionTax
    ElseIf optIcedLatte.Value Then
        lblItemAmount = FormatCurrency(2.5 * txtQuantity)
        Call SubtotalSectionNoTax
    End If
   
    If optIcedCappuccino.Value And chkTax.Value = 1 Then
        lblItemAmount = FormatCurrency(2.5 * txtQuantity)
        Call SubtotalSectionTax
    ElseIf optIcedCappuccino.Value Then
        lblItemAmount = FormatCurrency(2.5 * txtQuantity)
        Call SubtotalSectionNoTax
    End If

End Sub


Private Sub cmdClear_Click()

txtQuantity.Text = " "
chkTax.Value = False
lblItemAmount.Visible = False
optCappuccino.Value = False
optEspresso.Value = False
optLatte.Value = False
optIcedLatte.Value = False
optIcedCappuccino.Value = False
End Sub

Private Sub mnuFileNew_Click()
Me.Hide
frmSummary.Shown
End Sub

Private Sub Load()
optCappuccino.Value = False
optEspresso.Value = False
optLatte.Value = False
optIcedLatte.Value = False
optIcedCappuccino.Value = False
End Sub

Private Sub SubtotalSectionTax()
Dim Subtotal As Single
Dim Tax As Single
Dim Total As Single
Tax = 0.0825
Subtotal = lblItemAmount
lblSubTotal = FormatCurrency(Subtotal)
Tax = FormatCurrency(lblItemAmount * Tax)
lblTax = FormatCurrency(Tax)
Total = Subtotal + Tax
lblTotal = FormatCurrency(Total)
End Sub
Private Sub SubtotalSectionNoTax()
Dim Subtotal As Single
Dim Tax As Single
Dim Total As Single
Subtotal = lblItemAmount
lblSubTotal = FormatCurrency(Subtotal)
Tax = 0
lblTax = FormatCurrency(Tax)
Total = Subtotal + Tax
lblTotal = FormatCurrency(Total)
End Sub
Avatar of bingie
bingie

Try not dimensioning the variables in each objects click event.

Meaning, add Option Explicit to the top of your code and dim the variables below

e.g.

Option Explicit
Dim Subtotal as Currency
Dim Tax as Single
......

Then set the variables equal to the Labels. If you just Dim them first and not every time you click the button it will retain the value.

bingie
Avatar of oteskl

ASKER

bingie, the above wasn't the solution to my problem.  But thanks for trying to help.

I have another question...  how can I get a value (text value) in one form to appear in another form?

ASKER CERTIFIED SOLUTION
Avatar of JonothanTompson
JonothanTompson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oteskl

ASKER

Example of my code below.
I can't get the gCount value from frmBilling to show up in frmSummary's lblCount.  When I pull up the frmSummary to see if lblCount got populated, I got the following error:  "Compile error:  Method or data member not found"

Sub Main()
frmSplash.Show vbModeless
Load Main
Public gCount As Integer
End Sub

*** frmBilling***
Private Sub cmdCalculate_Click()
    If optCappuccino.Value Then
        'Counter
        gCount = txtQuantity
        picDisplay.Print gCount
    End if
End Sub

***frmSummary***
Private Sub mnuFileSummary_Click()
Call cmdCalculate_Click
Me.Hide
frmSummary.Show
Dim Average  As Currency
If frmBilling.gCount > 0 Then
    Average = Total / frmBilling.gCount
Else
    Average = 0
End If
lblCount = frmBilling.gCount
lblAverage = FormatCurrency(Average)
End Sub
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, just a clarification.
When refering to text entry in textbox, use text1.text
for label, use label1.caption

~ fantasy ~
Avatar of oteskl

ASKER

Thanks all for helping!