Solved

VB 6.0 question

Posted on 2003-11-09
8
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Assisted Solution

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

form1.textbox1.value

~ fantasy ~
0
 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 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