IF-statements

Post your coding questions such as 'how to' here.
Post Reply
rafleo

IF-statements

Post by rafleo »

It's me again... and I need help, as usual...

It seems as if I'm too stupid to make a correct "IF-statement", but I searched the whole documentation and the translated manuals in the forum, but I couldn't find one example of how to do it.

I tried this:

Code: Select all

numbers$ = ReadConfig("nums.cfg","var1")
num1$ = Right(numbers$, 2)


If num1$ = 20 Or num1$ = 25 Or num1$ = 40 Or num1$ = 50
    ...Do something...
Else 
    ...do something else...
EndIf
What am I doing wrong?
The script always does the statements of the "Else" section, but never the "If" section, even if it's true.

Thanks for your patience and help...
Harakka
Advanced Member
Posts: 430
Joined: Mon Aug 27, 2007 9:08 pm
Location: Salo
Contact:

Re: IF-statements

Post by Harakka »

The num1$ variable is string type so it contains text. Your if-statement looks for real numbers. It should work if you convert the variable to an integer with int().

Code: Select all

numbers$ = ReadConfig("nums.cfg","var1")
num1$ = Right(numbers$, 2)

intnum = int(num1$)
If intnum = 20 Or intnum = 25 Or intnum = 40 Or intnum = 50
    ...Do something...
Else 
    ...do something else...
EndIf
This might work, too:

Code: Select all

numbers$ = ReadConfig("nums.cfg","var1")
num1$ = Right(numbers$, 2)


If num1$ = "20" Or num1$ = "25" Or num1$ = "40" Or num1$ = "50"
    ...Do something...
Else 
    ...do something else...
EndIf
Peli piirtokomennoilla - voittaja, Virtuaalilemmikkipeli - voittaja,
Sukellusvenepeli - voittaja, Paras tileset - voittaja
Vaihtuva päähenkilö - voittaja, Autopeli - voittaja sekä
Hiirellä ohjattava peli - voittaja B)
rafleo

Re: IF-statements

Post by rafleo »

thanks, works perfectly.
Karlgamer
Newcomer
Posts: 4
Joined: Fri Feb 08, 2008 11:05 pm

Re: IF-statements

Post by Karlgamer »

I always use "then" in my if statements... it helps me logically think it out.

if she isn't to young then I can date her or else I run away

Code: Select all

if Girlage > 19 then 
     distance = 0
else
     distance  = 1000000000000
end if
Post Reply