Archived

This topic is now archived and is closed to further replies.

jedi2832

Visual Basic

Recommended Posts

Private Sub cmdExit_Click() End End Sub Private Sub cmdPurchase_Click() Dim x As Integer y = 0 x = Val(InputBox("Enter Your Age: ")) If x < 12 And x >= 1 Then MsgBox ("$ ") & 5.5 y = y + 1 ElseIf x > 55 And x <= 200 Then MsgBox ("$ ") & 6.5 y = y + 1 ElseIf x >= 12 And x <= 55 Then MsgBox ("$ ") & 7.5 y = y + 1 Else MsgBox "Error!", vbCritical End If MsgBox y End Sub Private Sub Form_Activate() Dim y As Integer End Sub in this code i try to get the y to add up, so every time a pop window comes up to ask your age, u enter ur age, and it converts how much money it cost, but i cant seem to add up the money, and tell the user, how much money total it gonna cost. plz help

Share this post


Link to post
Share on other sites
You need to define y as a public variable.
At teh moment, you get a new y every time you click the Purchase Button.
remove the Dim y as integer from teh activate sub, and then add Public y as integer at teh top of your form code OUTSIDE ALL SUBS

look up variable scope is any good programming textbook/intenet site etc....



-----------

Does it matter? Even if it does matter, does it matter that it matters?

Share this post


Link to post
Share on other sites
from that code y will always =
a msgbox will appear telling you how much!!

what is the point of Y?

do you want y to hold this info all the time?

if so declare it like this

static y as integer

then everytime the code is excuted y will hold the value of the time before.

posted the same time as above

[edited by - themonkster on October 13, 2003 6:40:40 PM]

Share this post


Link to post
Share on other sites
Dim y As Integer
Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdPurchase_Click()
Dim x As Integer
x = Val(InputBox("Enter Your Age: "))
If x < 12 And x >= 1 Then
MsgBox ("$ ") & 5.5
y = y + 5.5
ElseIf x > 55 And x <= 200 Then
MsgBox ("$ ") & 6.5
y = y + 6.5
ElseIf x >= 12 And x <= 55 Then
MsgBox ("$ ") & 7.5
y = y + 7.5
Else
MsgBox "Error!", vbCritical
End If
MsgBox y
End Sub

Private Sub Form_Activate()
Static y As Integer
End Sub

this time it worked, thx alot guys

Share this post


Link to post
Share on other sites
you realize that you aren''t adding up the money. All you are doing is adding amount of customers.

If it''s still not working post your new code.

Share this post


Link to post
Share on other sites
one more thing, every time 3 of those number added, the computer always rounded off, not leaving a .5, is there anyway i can have it leave a .5 when odd numbers are added, thx for replying

Share this post


Link to post
Share on other sites