PDA

View Full Version : IF/THEN problem



catventure
28-11-2005, 16:37
Hi,

Built a new function into my adventure project to deal with game settings and have come up against an if/then error by thinbasic:



Script Run Time Error
error code 9
THEN expected
Line code 'If tempval>0 & tempval<501 THEN

token found TEMPVAL


On the TB StatusBar it says: THEN expected: TEMPVAL

Extract from my function code:



control get text hdlg, 930 to tempstr
tempval=val&#40;tempstr&#41;
if tempval >0 & tempval <501 then
startloc=tempval
else
msgbox &#40;0,"Invalid Location Number",%MB_OK or %MB_ICONEXCLAMATION,"T.A.B. Information"&#41;
end function
end if


tempval is global and have used it in other funcs without any errors like this before.

I'll continue trying to hunt down the cause...


catventure.

catventure
28-11-2005, 18:13
No luck yet :(

I should have used 'EXIT FUNCTION' instead of end function as below



control get text hdlg, 930 to tempstr
tempval=val&#40;tempstr&#41;
if tempval >0 & tempval <501 then
startloc=tempval
else
msgbox &#40;0,"Invalid Location Number",%MB_OK or %MB_ICONEXCLAMATION,"T.A.B. Information"&#41;
EXIT function
end if


but still the error persists...

Will continue to try and track it down


catventure

catventure
28-11-2005, 18:33
Found it!

You must use 'AND' and not '&' in IF/Then statements...

Forgot about that

This was incorrect:



if tempval >0 & tempval <501 then


This is correct syntax:



if tempval >0 AND tempval <501 then


Why it take me so long to work it out?
Sometimes you cannot see the wood for the trees!!! :roll:

catventure