Solved

VB 6.0 question

Posted on 2003-11-09
8
353 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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