03-13-2019 03:33 PM
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.
03-15-2019 04:39 PM
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
03-21-2019 03:29 PM
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.