Source language: Translate to:

If and IfEx Statements

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

If and IfEx Statements

Postby redjr » Thu Oct 15, 2009 11:39 am

I'm curious about a better to construct an IfEx statement and was wondering if it's possible.

I want to compare a variable against 3 numbers without having to repeat the variable - for instance... is there a way of grouping multiple values like this....

IfEx "[Account] = (123, 456, 789)"
GotoPage "Balance"
Else
AlertBox "No records for these accounts."
EndIf


Thanks,
redjr...
User avatar
redjr
 
Posts: 80
Joined: Tue Jan 06, 2009 2:49 pm
Location: NY

Postby smartmedia » Thu Oct 15, 2009 12:22 pm

Hi..

Try that.

IfEx "[Account] = 123 OR [Account] = 456 OR [Account] = 789"

this will do the job.
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby redjr » Thu Oct 15, 2009 12:46 pm

smartmedia wrote:Hi..

Try that.

IfEx "[Account] = 123 OR [Account] = 456 OR [Account] = 789"

this will do the job.


I recognize that's the standard syntax of doing it. I'm trying to elliminate having to repeat [Account] for each test, hence the (123, 456, 789). But there may not be any other way.

The standard method takes up a lot more space on the line and can be hard to read if you have numerous values you are testing for. I suppose I could set up some kind of list with the values and then create an array, but that may be more cumbersome than its worth too.

Thx,
redjr...
User avatar
redjr
 
Posts: 80
Joined: Tue Jan 06, 2009 2:49 pm
Location: NY

Postby smartmedia » Thu Oct 15, 2009 1:16 pm

Hi..

I suppose that you want to check lot's of numbers at once. If you know all the numbers you can write them all in a text file, line by line, read them with a loop and make the check. This is the easiest way.
If you want to try one other approach, is to create a database with a table and a field and use a simple or a sophisticate seach.
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby Ndzn » Mon Oct 19, 2009 4:24 am

The correct way is with the long, but accurate, syntax... But, another way to do what you're asking, similar to smartmedia's suggestion but without a separate file or db, is to...

Code: Select all
.1) Create a delimited string of the values you want to check against.
.    (This string can also be created programmatically)
SetVar "[ValStr]" "123,456,789,876,543,210"

.2) Parse the string to an array
StrParse "[ValStr]" "," "[Val]" "[Val_Count]"

.3) Loop the length of the array checking each value
.    When a mismatch is encountered Set a "Score" value
Loop "1" "[Val_Count]" "[x]"
   If "[Account]" "<>" "[Val[x]]"
      SetVar "[Score]" "[Score]+1"
   EndIf
EndLoop


.4)
. Check if "Score" has a value
If "[Score]" ">" "0"
. There was a mismatch
. Do something here
EndIf




I suppose this really has little to do with your initial request or question, and there are probably other ways to do this, but thought I'd toss this sample code out here for the sake of discussion.
User avatar
Ndzn
 
Posts: 134
Joined: Sun Sep 20, 2009 8:37 am

Postby redjr » Mon Oct 19, 2009 9:58 am

Ndzn wrote:The correct way is with the long, but accurate, syntax... But, another way to do what you're asking, similar to smartmedia's suggestion but without a separate file or db, is to...

Code: Select all
.1) Create a delimited string of the values you want to check against.
.    (This string can also be created programmatically)
SetVar "[ValStr]" "123,456,789,876,543,210"

.2) Parse the string to an array
StrParse "[ValStr]" "," "[Val]" "[Val_Count]"

.3) Loop the length of the array checking each value
.    When a mismatch is encountered Set a "Score" value
Loop "1" "[Val_Count]" "[x]"
   If "[Account]" "<>" "[Val[x]]"
      SetVar "[Score]" "[Score]+1"
   EndIf
EndLoop


.4)
. Check if "Score" has a value
If "[Score]" ">" "0"
. There was a mismatch
. Do something here
EndIf




I suppose this really has little to do with your initial request or question, and there are probably other ways to do this, but thought I'd toss this sample code out here for the sake of discussion.


Very good. This will work as well, just involves a bit more code. Anyway, it's good to have other examples and techniques in my 'toolbox'.

redjr...
User avatar
redjr
 
Posts: 80
Joined: Tue Jan 06, 2009 2:49 pm
Location: NY


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron