12-08-2011 01:37 AM
Hi,
I have a string with a numeric value content which I have extracted out (using Mid()) into a separate value but instead of using a String variable I have actually used a Numeric. So should this have caused an error? (see attached example)
12-08-2011 04:34 AM
Ray,
you are correct that from all infos available in the documention, this should create an error.
Nevertheless, i think i have found the reason why it does NOT throw an error:
Obviously, assigning a string variable containing solely numeric characters (including decimal point) will automatically cast the data type. This is an "implicit" type cast, but it only works in one direction: String => Number.
So it seems, that "val()" is not necessary (anymore?), but "str()" is still needed.
I did not find any information about when this feature was "reintroduced", i only found that back in TS 1.0, neither val() nor str() was necessary. As of TS 2.0, it was stated that both functions are mandatory for type casts....
hope this helps,
Norbert
12-08-2011 04:52 AM
Thanks Norbert.
I wonder if it's wise to use the Val() anyway or is this going to be the norm.
12-08-2011 11:03 AM - edited 12-08-2011 11:04 AM
Types are generally implicitly converted on assignment in TestStand expressions and always have been. Strings can be assigned directly to numbers and numbers can be assigned directly to strings. To maintain backwards compatibility, it is unlikely this will ever change. Note that the new Int64 and UInt64 representations do not allow this implicit conversion in order to avoid unintended consequences and unintended loss of precision. Since Int64 and UInt64 are new types, there is no backwards compatibility issue.
Val() and Str() are still needed for things like passing parameters. Also Val() and Str() offer additional information and options that you don't get with the implicit conversion.
Hope this helps explain things,
-Doug