Solved

VB 6.0 question

Posted on 2003-11-09
8
356 Views
Last Modified: 2010-05-03
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
0
Comment
Question by:oteskl
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:bingie
ID: 9710884
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
0
 

Author Comment

by:oteskl
ID: 9711956
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?

0
 
LVL 1

Accepted Solution

by:
JonothanTompson earned 40 total points
ID: 9712124
You can either call the lable or text box on the other form ie.
Form2.txtValue.Text = *** insert the variable
or you could set up a global in a module variable and set that and access that from the other from
Using globals maybe an answer to your other problem
0
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 30 total points
ID: 9712131
try to reference to the form

form1.textbox1.value

~ fantasy ~
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:oteskl
ID: 9712215
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
0
 
LVL 11

Assisted Solution

by:bingie
bingie earned 30 total points
ID: 9714528
Change this

gCount = txtQuantity

to

gCount = txtQuantity.text

Or you could just change the second block of code from

If frmBilling.gCount > 0 Then

to

If frmBilling.txtQuantity.text > 0 Then


0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9718959
Ok, just a clarification.
When refering to text entry in textbox, use text1.text
for label, use label1.caption

~ fantasy ~
0
 

Author Comment

by:oteskl
ID: 9727016
Thanks all for helping!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now