Sign in to follow this  
SteveMyres

AscA not working as expected in execute()

Recommended Posts

Manually entering

MyChannelName.Addvalue(AscA(MyString))

works (it pushes all the ASCII codes in as consecutive channel points), but if I place it in an execute(), it seems to build the script string with only the ASCII value for the first character, rather than AscA(strArg) evaluating to a numeric array (as if I used Asc())

execute(ChannelName + ".Addvalue(" + AscA(strArg) + ")")

Evaluate does the same thing -- treats the AscA() as if the string were only one character.

Share this post


Link to post
Share on other sites

Actually the problem isn't with asca().  The problem is that string concatenation doesn't support arrays.  So even:

? "array: " + {1,2,3} + " end array"

will print:

array: 1 end array

The problem is that DAQFactory doesn't really know how you want to present the array.  Do you want a comma delimited list?  With brackets or without?  Space after the comma?  Etc.  Plus, beginners often really only want [0], especially when using channels, but forget to do so.  So:

"My Value: " + myChannel

will do the same as:

"My Value: " + myChannel[0]

So, in your case, what you really need to do is keep the asca() in the quotes:

execute(ChannelName + ".AddValue(asca(" + strArg + "))")

that way the concatenation doesn't involve the array.  

But then, why are you pulling out strArg anyway?  Remember, execute() runs in the scope of the call script, so you should be able to reference strArg from within the string:

execute(ChannelName = ".AddValue(asca(strArg))")

 

Share this post


Link to post
Share on other sites

Oh!  Duh, don't know why I was doing that.  Just in the habit of evaluating everything down to a final answer before concatenating (primarily for the creation of display strings and so on).

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this