DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Text Array to Numeric Channel

I have a text array variable (with numbers) that I would like to end up as a numeric channel and I cannot figure out the most efficient way to do this - I suspect there is a great solution that eludes me.  I can use ArrayToChannels, but this creates a text channel.  Can I use ChnCalculate to convert a text channel to numeric somehow?  I have tried a few things, but nothing has worked yet. 
 
My example:

Dim NewArray, NewChns
NewChns = "NewChannelName" : NewChns = Split(NewChns, "|")
NewArray = "1|2|3|4|5" : NewArray = Split(NewArray, "|")
Call ArrayToChannels(NewArray, NewChns)
' Results in text channel
 
0 Kudos
Message 1 of 8
(4,209 Views)

Hi Julia,

here is a brute force solution:

Dim NewArray, NewChns
NewChns = "NewChannelName" : NewChns = Split(NewChns, "|")
NewArray = "1|2|3|4|5" : NewArray = Split(NewArray, "|")
Dim i
For i = 0 To UBound(NewArray)
  NewArray(i) = CDbl(NewArray(i))
Next
Call ArrayToChannels(NewArray, NewChns)
' Results in numeric channel

May be that helps,

Christian

0 Kudos
Message 2 of 8
(4,205 Views)

Hi Christian,

Thanks for the speedy reply - unfortunately that is very similar to what I am already doing, and I was hoping for something better.  But if this is the only way, this is how it will have to be!

Thank you again,

Julia

0 Kudos
Message 3 of 8
(4,204 Views)

Obviously, it is sufficient to set the data type of the first array element to double:

NewArray(0) = CDbl(NewArray(0))
Call ArrayToChannels(NewArray, NewChns)

Christian

0 Kudos
Message 4 of 8
(4,198 Views)
That works!  Thanks again 🙂
0 Kudos
Message 5 of 8
(4,195 Views)
Hello Julia!
 
Another aproach is to convert the text channel into a numeric channel via DataBlClpCopy/DataBlClpPaste. The numeric target channel must exist.
 
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 6 of 8
(4,190 Views)

Hi All,

Another possibility in DIAdem 10.1 or later is to use the new ChnCalculate() command:

Call ChnCalculate("Ch(""[1]/Name"") = CDbl(Ch(""[1]/Name"")))

But I think Christian's suggestion is the most efficient,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 7 of 8
(4,166 Views)
Hello Brad!
 
Can you guarantee that Christian's second version will work in future DIAdem versions?
 
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 8 of 8
(4,162 Views)