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.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert string channel to hexadecimal values

Hi,

 

I'm trying to convert a string channel to hexadecimal values using a VBS script.

If I use the channel name directly into the equation, the script works fine and I can convert the channel into hexadecimal values.

Call Calculate("ch(""[1]/variable_new"") = CLng(""&H"" & ch(""[1]/variable""))")

 

However, I want to select first the channel into the Data portal, and the run the script over the selected channel

For Each oElem in Portal.Structure.Selection

str1 = oElem.Name

str2 = oElem.Name & "_new"

Call Calculate("ch(str2) = CLng(""&H"" & ch(str1))")

next

 

I get the following error when I run the script:

Error message from DIAdem command kernel:

Cannot execute calculation because the input channel "CH()" is unknown"

 

Does anybody know how to solve this problem?

 

Thanks in advance.

 

 

 

0 Kudos
Message 1 of 3
(2,126 Views)

Hi Luariza,

 

You're close.  The only thing tripping you up is the regular VBScript variables are not accessible in the formula text of the Calculator function.  Instead, you have to use a DIAdem global variable.  There are several ways to create and use DIAdem global variables, but the simplest approach is just to use one of the temporary variables that DIAdem always declares at startup, like this:

 

For Each oElem in Portal.Structure.Selection
T1 = oElem.Name
T2 = oElem.Name & "_new"
Call Calculate("ch(T2) = CLng(""&H"" & ch(T1))")
next

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 2 of 3
(2,082 Views)

Hi Brad, thank you for your answer.

unfortunately, your proposal didn't work... 😞

 

Anyway, finally I found a solution to my problem.

For Each oElem in Portal.Structure.Selection
     Dim str1: str1 = "Ch(""[1]/" & oElem.Name & """)"
     Dim str2: str2 = "Ch(""[1]/" & oElem.Name & "_new" & """)"

     Formula = str2 & "= CLng(""&H"" & " & str1 & ")"
     Call Calculate(Formula)
next

Regards,

Gorka.

0 Kudos
Message 3 of 3
(2,047 Views)