Hi, I think the SCMP command is failing because of the decimal place. If you take that out you will see it work correctly.
FOO = "401010" BAR = "40101000" CRT SCMP(FOO,BAR) -1 FOO = "401010" BAR = "401010" CRT SCMP(FOO,BAR) 0 FOO = "4010100" BAR = "401010" CRT SCMP(FOO,BAR) 1 SCMP RESULT FOO < BAR = -1 FOO = BAR = 0 FOO > BAR = 1 From: Rob Sobers <[email protected]> To: U2 Users List <[email protected]> Date: 12/08/2011 13:16 Subject: [U2] Comparing numeric strings Sent by: [email protected] Say you have two strings that happen to be nuneric: FOO = "401.0101" BAR = "401.0101000" Since UniBasic is untyped, even though I've wrapped each value in quotes "", they are treated as numbers. As a result, FOO EQ BAR evaluates to @TRUE. In most dynamically typed languages, there's an intuitive way to coerce the values at run-time (e.g, foo.to_s, foo.ToString, Str(foo)). I can't seem to figure out a good way to do this in UniBasic. In the manual, there's a function called SCMP that is supposed to be handy for comparing numeric strings, but it doesn't appear to work in UniData 7.2. # First try SCMP IF SCMP(FOO, BAR) THEN CRT "Not Equal" END ELSE CRT "Equal" END # Now try EQ IF FOO EQ BAR THEN CRT "Equal" END ELSE CRT "Not Equal" END Result: Equal Equal Also, the "tip" in the manual seems to be untrue: "Numbers specified in quotation marks are string data type. Numbers specified without quotation marks are numeric data type. The data type in a variable is determined by the data first loaded into it." Quotation marks appear to have absolutely no bearing on data type. -Rob _______________________________________________ U2-Users mailing list [email protected] http://listserver.u2ug.org/mailman/listinfo/u2-users _______________________________________________ U2-Users mailing list [email protected] http://listserver.u2ug.org/mailman/listinfo/u2-users
