First code issues
dieseldave1984
Posts: 2
Hello all, I am just now working on my first program and cannot figure out this part of code below in red, also if anyone has any tips to clean it up some. I will have several of these full statements listed below on a repeat loop checking the first line "if(psi<,>,== a number) " it will run the code below it and if not will check the next "if(psi<,>,== a number) in the loop to see if its true/false and run the secondary code. Any help is greatly appreciated, thanks!
if(psi < 100)
if (position < 400)
direction :=1
pst.str(string("set1"))
pst.newline
elseif (position > 500)
direction :=2
pst.str(string("set2"))
pst.newline
if (position == (401..499)) <==== I need the code to check if its between 401-499 and every number in between those (if thats even posible)
direction :=3
pst.str(string("set3"))
pst.newline
if(psi < 100)
if (position < 400)
direction :=1
pst.str(string("set1"))
pst.newline
elseif (position > 500)
direction :=2
pst.str(string("set2"))
pst.newline
if (position == (401..499)) <==== I need the code to check if its between 401-499 and every number in between those (if thats even posible)
direction :=3
pst.str(string("set3"))
pst.newline
Comments
Make sure and keep the "=" and "<>" signs in the correct order. "=<" and "<=" are not the same.
Another is with the case statement.
Since indentation is part to the syntax in Spin, it's important to use code tags when posting code.
Phil made a tutorial on how to post code. Here's a link.
By starting at one end of the possible values and working towards the other, you can eliminate the need of using "and" as the example in post #2.
For example, by starting at the smallest group you want to test against and working your way up, you don't need to exclude the lower range since if the value had been lower, the code would found a match and stopped checking the higher values.
Of course it's important to use "elseif" and not just a series of "if" statements.