Using an Integer To Store a number
Hi, i am just woundering if anyone can help me i am working in VB6.
i am wanting to store a number like pounds in a integer and then lets say the player wishes to buy somthing like a oven that costs £599 and as 1000 starting money this is the code but its not working does anyone know why.
General Decorations
VB Code:
'Integer that Stores record of the players money
Dim intmoney As Integer
VB Code:
Private Sub Form_Load()
'This sets the players money to 1000 for starting money when the form loads
intmoney = 1000
end sub
VB Code:
Private Sub oven2_Click()
If intmoney >= 599 Then lockOven2.Visible = False
intmoney = -599
Label4.Caption = "You Bought The New Item"
If intmoney < 599 Then Label4.Caption = "Sorry But You Can Not Afford This Item"
End Sub
by the way lockOven2 is a label that is covering and hiding the second oven gaphic so with that not visible you second oven will be.
sorry if this is a bit of an low level vb question
thanks in advance
pipwilky
Re: Using an Integer To Store a number
Nearly there, try this:
VB Code:
Private Sub oven2_Click()
If intmoney >= 599 Then
lockOven2.Visible = False
intmoney = intmoney - 599
Label4.Caption = "You Bought The New Item"
Else
Label4.Caption = "Sorry But You Can Not Afford This Item"
End If
End Sub
Re: Using an Integer To Store a number
Shouldn't it be?
VB Code:
'...
intmoney = [B]intmoney[/B] - 599
'...
Re: Using an Integer To Store a number
You didn't say what was not working but I'm guessing that the amount of money in intMoney isn't correct. If so then it looks like this is what you want to do.
VB Code:
Private Sub oven2_Click()
If intmoney >= 599 Then lockOven2.Visible = False
[HL="#FFFF80"]intmoney = intmoney - 599[/HL]
Label4.Caption = "You Bought The New Item"
If intmoney < 599 Then Label4.Caption = "Sorry But You Can Not Afford This Item"
End Sub
Re: Using an Integer To Store a number
It should be like this:
VB Code:
Private Sub oven2_Click()
If intmoney < 599 Then
Label4.Caption = "Sorry But You Can Not Afford This Item"
ElseIf intmoney >= 599 Then
lockOven2.Visible = False
intmoney = intmoney - 599
Label4.Caption = "You Bought The New Item"
End If
End Sub
Pradeep :)
EDIT: :eek: so many posts in one go!
Re: Using an Integer To Store a number
that you very much for all your replys and kind help.. ill will have go home and try these because my internet's down so i have to go to my mums.....as soon as i have tested theese codes i will post as RESOLVED or not.
big thanks to :-
Rob123
gavio
MartinLiss
Pradeep1210
for all your help, imput and advise.
regards pipwilky