Shorten Code..?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Shorten Code..?

Post by topcat888 » Wed Jan 13, 2010 12:37 pm

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
Last edited by topcat888 on Wed Jan 13, 2010 1:37 pm, edited 2 times in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Shorten Code..?

Post by FourthWorld » Wed Jan 13, 2010 1:10 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Shorten Code..?

Post by topcat888 » Wed Jan 13, 2010 1:28 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Shorten Code..?

Post by FourthWorld » Wed Jan 13, 2010 2:50 pm

Your "if" statement has no comparison operator.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Shorten Code..?

Post by topcat888 » Wed Jan 13, 2010 3:25 pm

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
Last edited by topcat888 on Wed Jan 13, 2010 3:29 pm, edited 1 time in total.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Shorten Code..?

Post by Klaus » Wed Jan 13, 2010 3:28 pm

Hi topcat,
...
if it mod 2 = 0 then
## even number
else
## uneven number
end if
...


Best

Klaus

Post Reply