Hey, im doing an assignment that requires to make a vending machine :eek: yeah, its all over here.

However can anyone tell me whats wrong with this code?

purchase = if price <= money Then
money = money - price
Else
If price >= money Then
TextBox1.Text = "Sorry! Not Enough Money!"
End If
'Fixing the money going into the minuses'
If money <= -1 Then
money = old_money
End If

I get an error with the first if, it says 'expression expected' havnt i dont that?

it also gives me an error with the Else, it says it needs a matching if.

thanks for any help

You are assigning a value to a varialbe with an IF statement. You can't do that try this:

if price <= money Then
    money = money - price
Else
    If price >= money Then
        TextBox1.Text = "Sorry! Not Enough Money!"
    End If
End If
'Fixing the money going into the minuses'
If money <= -1 Then
money = old_money
End If

I would change the money<=-1 to money<0 to cover -.01.

instead of rewriting the code -with different logic.jusr write has follows
if(condn1)
elseif(condn2)
elseif(condn3)
stmt1
else
stmt2
endif
----------------
thats it!!!

instead of rewriting the code -with different logic.jusr write has follows
if(condn1)
elseif(condn2)
elseif(condn3)
stmt1
else
stmt2
endif
----------------
thats it!!!

purchase = if price <= money Then

This is wrong.

if price <= money Then

is right. Try it and it should work

Hi

check this:

if price <= money Then
    money = money - price
Else
    TextBox1.Text = "Sorry! Not Enough "
End If
If money <= -1 Then
    money = old_money
End If

Regards
Veena

This article has been dead for over six months. Start a new discussion instead.