Page 1 of 1

Using "is not", is this correct?

Posted: Wed May 13, 2009 10:01 pm
by gyroscope
Hi, I might be missing something obvious here: part of my app registration code is:

Code: Select all

 if tB312 is not "41" or tB312 is not "58" or tB312 is not "94" or tB312 is not " 34" or tB312 is not "44" or tB312 is not "18"\
         or tB312 is not "26" or tB312 is not "17" or tB312 is not "32" or tB312 is not "75" or tB312 is not "82" or tB312 is not "88" then
        beep
     answer "Sorry, this is not a valid code for ISAGO"
     exit mouseUp
  end if
But if part of the registration code contains any of those numbers it still answers that it's not valid. Have I misunderstood "is not" , perhaps, could anyone tell me please, or is there some other reason this bit of code isn't working :?:

Posted: Wed May 13, 2009 10:33 pm
by Mark
Hi Gyroscope,

Replace or with and.

Best,

Mark

Posted: Wed May 13, 2009 10:37 pm
by gyroscope
Ah, I knew it'd be something obvious, thank you Mark!

:)

Posted: Wed May 13, 2009 11:03 pm
by whelkybaby
I'm intrigued by the really long "if" statement. You could consider simplifying this code a little by using "if ... is [not] in".

For example:

Code: Select all

if tB312 is not in "41,58,94,34,44,18,26,17,32,75,82,88" then
    beep
    answer "Sorry, this is not a value code to ISAGO"
    exit mouseUp
end if
Regards,


Steve

Posted: Wed May 13, 2009 11:12 pm
by gyroscope
Much better than my version Steve, thank you. Clearer to read too.

:)

Posted: Wed May 13, 2009 11:18 pm
by whelkybaby
No problem!

After reading a post the other day about us lurkers never posting to the board, I thought I'd try to make more of an effort!

Cheers,


Steve

Posted: Wed May 13, 2009 11:25 pm
by Mark
Hi Steve and gyroscope,

Code: Select all

if tB312 is not in "41,58,94,34,44,18,26,17,32,75,82,88" then 
will return return false whenever tB312 equals any character that is in "41,58,94,34,44,18,26,17,32,75,82,88", including 1, 2, 3, 4, 5, 6, 7, 8, 9 and comma. To avoid this, you can use the following:

Code: Select all

set the itemDel to comma // if necessary
if tB312 is not among the items of "41,58,94,34,44,18,26,17,32,75,82,88" then 
Best regards,

Mark

Posted: Thu May 14, 2009 4:44 pm
by gyroscope
That's neat Mark, thanks again.

:)