From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Maximum value as a number and not string

Solved!
Go to solution

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...

 

 

 

 

 

0 Kudos
Message 1 of 6
(5,733 Views)

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

0 Kudos
Message 2 of 6
(5,712 Views)
Solution
Accepted by topic author LePot

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

0 Kudos
Message 3 of 6
(5,706 Views)

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

 

 

0 Kudos
Message 4 of 6
(5,697 Views)

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

0 Kudos
Message 5 of 6
(5,688 Views)

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.

 

 

 

 

0 Kudos
Message 6 of 6
(5,671 Views)