08-23-2014 08:40 AM
I calculated the maximum value of a channel. The next step is to use that value for further calculation. My problem is that i cant use that value as a number. Its just a string. I tried it with
ChnPropGet so that i got the number. But I cant use it for calculations. Does anybody have an idea how i can solve that problem?
I attach a screenshot of my Skript. I use the german version of DIAdem 12.
Thanks for help...
Solved! Go to Solution.
08-24-2014 07:42 AM
The cdbl command will convert to double subtype, from which you can do calculations.
I have found that using the first char of a variable name for type, helpful. given the untyped nature of VBscript.
i for integer
d for double
s for string
08-24-2014 03:32 PM
the properties.Value function returns teh property in its native type. If you access the maximum property of a channel it will return the value as a floating point number. You can check this by running the following script:
(The script assumes that teh example dataset is load which has a group number 3 with a channel named "Res_Schall_1". But your channels should give you the same result with the messagebox showing "double"
Maximum = Data.Root.ChannelGroups(3).Channels("Res_Schall_1").Properties("minimum").Value
Should you ever want to convert from a number represented as a string, be careful when using "CDbl". This VBScript function assumes that the number is formatted using the locale setting from oyur OS, especially the decimal delimiter (being "." or ",") . If the setting in the OS doesn't match the way teh number was converted into a string, you have a problem. This is why DIAdem offers str() to go from a number to s string and Val() to go the opposite direction. Using CDbl can create rellay mean errors which are hard to detect.
08-24-2014 05:45 PM
Very good posts to your question have been made.
I also like Val and str, Another one that is useful is "IsNumeric"
It can be used to test if a value in a numeric and then appropriate action taken.
if (isnumeric(Value)) then
dNum = Val(Value)
This allow you to test that a string is a actual number before a conversion is tried.
There are other "is" functions that are also very useful. Especially the "isNull" as you can not do a comparision to a null value, you can only use the isnull function.
08-25-2014 01:12 AM
I havent realized this problem.
when i check this cahnnelproperty I get a true:
call msgbox( isnumeric(Data.Root.ChannelGroups(1).Channels("Geschwindigkeit").Properties("maximum").Value) )
If there wouldn't be a true you normaly can use this string as a number for operations.
dim a : a = "3"
call msgbox( a+2 ) ' this returns a 5
Of course a real typecast and check is the best way to prevent from errors.
AE NI Germany
08-25-2014 03:45 AM
Thank u all for help. Actually u are right. Its already a double. So it works.
But at least i know how to figure out what kind of type are my variable now and I know how to convert them.