Page 1 of 1

Shorten Code..?

Posted: Wed Jan 13, 2010 12:37 pm
by topcat888
Hi,

Is it possible to shorten code like this..?

Instead of saying all this:

Code: Select all

 if field "lastNum1" > 18 and field "lastNum1" <37 and field "lastNum2" > 18 and field "lastNum2" <37 and field "lastNum3" > 18 and field "lastNum3" <37 and field "lastNum4" > 18 and field "lastNum4" <37 and field "lastNum5" > 18 and field "lastNum5" <37 and field "lastNum6" > 18 and field "lastNum6" <37 then put "High" into field "fldOut"
I could just say something like

Code: Select all

if field "lastNum1" to field "lastNum6" = > 18 but < 37  then put "High" into field "fldOut"
See what I mean..?

Thanks

Re: Shorten Code..?

Posted: Wed Jan 13, 2010 1:10 pm
by FourthWorld
You could use a repeat loop:

Code: Select all

on CheckValues
  repeat with i = 1 to 6
    get field ( "lastNum"&i)
    if it  >= 18 and it  < 37  then
        put "High" into field "fldOut"
        exit repeat
    end if
  end repeat
end CheckValues

Re: Shorten Code..?

Posted: Wed Jan 13, 2010 1:28 pm
by topcat888
Hi

Thanks for that but I get an error for checkValues line..? I've looked in the Dictionary and it isn't there..?

card id 1002: compilation error at line 43 (if: error in command) near "on", char 1..?

Also is it possible list certain numbers within the code you provided, for example I would like to check to see if the numbers returned within lastNum 1 to 6 is an even number...? Does it understand "even numbers" or do I have to give it a list of actual numbers in which case how dod you list groups of numbers..?

Code: Select all

on CheckValues
  repeat with i = 1 to 6
    get field ( "lastNum"&i)
    if it 2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36 then
        put "Even" into field "fldOut"
        exit repeat
    end if
  end repeat
end CheckValues

Thanks

Re: Shorten Code..?

Posted: Wed Jan 13, 2010 2:50 pm
by FourthWorld
Your "if" statement has no comparison operator.

Re: Shorten Code..?

Posted: Wed Jan 13, 2010 3:25 pm
by topcat888
Sorry..?? Are you refering to the first part of my question..? This would be great if you could answer this at present it will not accept on CheckValues - please see the error below..?

Code: Select all

card id 1002: compilation error at line 43 (if: error in command) near "on", char 1
-----------------------------------------------------------------------------------------------------------

or the second part of the question..? In which case instead of saying

Code: Select all

if it  >= 18 and it  < 37  then
how do I say

Code: Select all

 if it is an even number then
....?

or

Code: Select all

if it is a number within this range 1,3,7,9,15,21 then
Thanks

Re: Shorten Code..?

Posted: Wed Jan 13, 2010 3:28 pm
by Klaus
Hi topcat,
...
if it mod 2 = 0 then
## even number
else
## uneven number
end if
...


Best

Klaus