Solved

VB 6.0 question

Posted on 2003-11-09
8
370 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

829 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