02-10-2011 05:42 PM
I'm getting this error when I run a numeric limit step. It happens to be a no adapter step, I'm just checking that another step which was doing some math yields an anwer in a certain range. I'm using a very similar set of steps in another sequence (just different variables) but this is the only one that is throwing the error. Does anybody know what might cause this? Thanks in advance.
02-11-2011 09:50 AM - edited 02-11-2011 09:51 AM
One or more of your variables likely are the wrong data type. What are the data types of your variables?
Also, make sure you check the data source tab incase you have customized that setting.
-Doug
02-11-2011 11:13 AM
The problem seems to be that in the Post expression I was setting a variable equal to the addition of two other variables (they were numbers in string format) and Teststand doesn't seem to like that. So I subtracted the variables and multiplied the subtracted variable by -1, and it seems to work.
x=y+z -> x=y-z*(-1)
Any idea why that is the case?
02-14-2011 10:36 AM
What you are seeing is because the '+' operator for strings means string concatenation, not addition.
It's best not to rely on TestStand's automatic type conversion because you can get unexpected results. For example:
Locals.Str1 = "4"
Locals.Str2 = "5"
Locals.Num = Locals.Str1 + Locals.Str2
Unexpectedly gives you 45 for the value of Locals.Num rather than 9 because the '+' first concatenates the strings and the result is then converted into a number.
You should instead explicitly convert your strings to numbers using the Val() expression function as follows:
Locals.Num = Val(Locals.Str1) + Val(Locals.Str2)
Or perhaps, better yet, don't store numbers in strings if you can avoid it, return them from your code modules as the actual numeric type. If you need to convert a number to a string in teststand you can use the Str() expression function.
Hope this helps,
-Doug