In a simple calculator exercise I’m doing with my class I need to know whether 
the string in a field is "0" vs. "0.” (The latter can occur when the user 
enters zero + dot into the calculator display field.) If it’s just “0” the next 
next number key press should replace the contents of the display field; if it’s 
“0.” the next number key should be placed *after* the display field. But if the 
contents of fld “display” is “0.”, all of the following evaluate as TRUE:

   fld “display” = “0.” # as expected
   fld “display" = 0 # makes sense, because right side of comparison is a number
   fld “display” = “0” # seems like this ought to be comparing string to string
   char 1 to 2 of fld “display” is “0” # Really?!
 
Shouldn’t there be a way to force a string comparison? I know LC tries to be 
all helpful about casting numerals as numbers, but what if I want to know if 
it’s the exact string?

I guess I could do this dance:

  if char 1 of fld “display” is “0” and char 2 of fld “display” is NOT “0” then…

It’s seems to complicated for such a simple thing, especially for explaining to 
novice programmers. Maybe I’m missing something obvious.

Devin


Devin Asay
Office of Digital Humanities
Brigham Young University

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to