From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
08-23-2014 08:40 AM
Hallo,
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
LePot
The cdbl command will convert to double subtype, from which you can do calculations.
Paul
I have found that using the first char of a variable name for type, helpful. given the untyped nature of VBscript.
as in:
i for integer
d for double
s for string
08-24-2014 03:32 PM
Hello LePot,
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"
Dim Maximum
Maximum = Data.Root.ChannelGroups(3).Channels("Res_Schall_1").Properties("minimum").Value
MsgBox(TypeName(Maximum))
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.
Andreas
08-24-2014 05:45 PM
Hello LePot
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.
Like
dim dNum
if (isnumeric(Value)) then
dNum = Val(Value)
end if
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.
Paul
08-25-2014 01:12 AM
Hi everybody,
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"
dim b
call msgbox( a+2 ) ' this returns a 5
Of course a real typecast and check is the best way to prevent from errors.
Kind Regards,
Philipp K.
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.