Call me a hack ... go ahead

"A":FOO < "A":BAR

"Numeric string" is an oxymoron in any language, I believe.

Sincerely,
David Laansma
IT Manager
Hubbard Supply Co.
Direct: 810-342-7143
Office: 810-234-8681
Fax: 810-234-6142
www.hubbardsupply.com
"Delivering Products, Services and Innovative Solutions"

-----Original Message-----
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Rob Sobers
Sent: Friday, August 12, 2011 8:15 AM
To: U2 Users List
Subject: [U2] Comparing numeric strings

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
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to