NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Should this return a numeric!!

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)

 

 

Regards
Ray Farmer
0 Kudos
Message 1 of 4
(2,744 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 4
(2,739 Views)

Thanks Norbert.

 

I wonder if it's wise to use the Val() anyway or is this going to be the norm.

Regards
Ray Farmer
0 Kudos
Message 3 of 4
(2,737 Views)

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

Message 4 of 4
(2,726 Views)