Visual Basic
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
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?
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?
Whats the new code?
Does it matter? Even if it does matter, does it matter that it matters?
Does it matter? Even if it does matter, does it matter that it matters?
Alternatively, just below
Dim x As Integer
you could declare:
Static y as integer
either way, get rid of "y=0"
ld
Dim x As Integer
you could declare:
Static y as integer
either way, get rid of "y=0"
ld
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]
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]
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
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
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.
If it''s still not working post your new code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement