maths in if/then statement?

stocky

Senior Member
Hi,

I'm trying to run a series of if/then statements to branch a program based on a value:
ie: if SSENSOR < SSTEP then branch1

I need to do the same for 2*SSTEP, 3*SSTEP & 4*SSTEP but get a syntax error indicated on the line:

if SSENSOR < SSTEP*2 then branch2 - same result for SSTEP*3 & SSTEP*4

Any suggestions on how to work around this - my brain is fudge at the moment!

:)
 

westaust55

Moderator
and try a structure like:

Code:
If test   = value1 then
  Goto Somewhere1             
Elseif test = value2 then
  Goto Somewhere2
Elseif test = value3 then 
  Goto Somewhere3
Elseif test = value4 then
  Goto Somewhere4
Else
  Goto Somewhere5
Endif
 

stocky

Senior Member
short on bytes for that i think.....time to try and lighten the rest of the code
I'm working with an 08m and I am @ 240 bytes now and have a word variable in EEPROM
 

stocky

Senior Member
and try a structure like:

Code:
If test   = value1 then
  Goto Somewhere1             
Elseif test = value2 then
  Goto Somewhere2
Elseif test = value3 then 
  Goto Somewhere3
Elseif test = value4 then
  Goto Somewhere4
Else
  Goto Somewhere5
Endif
I am looking to branch for values under multiples of a stored variable (SSTEP)
SSTEP will be different each time the CAL routine is run so I need to be able to work out a way making the if/then use a mutiple of that stored var
 

westaust55

Moderator
The If. . . Then that I gave was a sample structure.

An alternative possibility is the

Select Case command (see manual 2 page 139)

Really need to see your code to help better
 

BCJKiwi

Senior Member
All the constructs like if, select, etc etc do not allow math within the tested value.

How about;
Code:
for b11 = 1 to 4
sstep = sstep*b11
If ssensor < sstep then exit
next
If b11 = 1 then goto test1:
If b11 = 2 then goto test2:
If b11 = 3 then goto test3:
If b11 = 4 then goto test4:
or any other construct of your choosing after the next - ie branch, select case, etc - but check program size as generally the nicer constructs actually use more code space than repeat if statements (depending on the number involved).

I'm sure if you posted your code the brains trust would do their best to fit it in the available space.
 

stocky

Senior Member
I'll post up a snippet tonite - got it working but its messy and I'm sure there is a neater way (liek the one given above!) :)
 
Top