Restricted variable names?


Recommended Posts

I had a strange issue with my sequence. 
I used two global string variables named "CurrX" and "CurrY". These were intended to dynamically specify X and Y expressions for graph traces. However, the sequence just wouldn't work, the traces would be added (as seen in the graph properties; no actual trace appeared on the graph), but both expressions would be shown as "NaN". When I tried seeing the current value of these variables (typing "?CurrX" in the command line), it would return the "NaN" value as well. 
As best as I could figure, everything else in the sequence was working as intended. Rather frustrated, I just replaced every instance of the "CurrX" by a different word, which should probably not be repeated here - and it fixed the issue. Same with "CurrY". 

As far as I've searched the user's guide, there's no mention of variable names beginning with "Curr" causing any problems - indeed, some of the examples therein use "current" as a variable name. Is there any reason why "CurrX" and "CurrY" cannot be used, and if so, is there a comprehensive list of any other reserved/unavailable variable names?

Link to comment
Share on other sites

My guess is what you did is declared currX and currY as numerical variables first, i.e.:

global currX

then realized your error and fixed it to:

global string currX

The problem is that once a variable is declared, you can't redeclare it as a different type.  Thus you get NaN because you are assigning some string to currX and currY that can't be converted to a number, like "x + y".  If you happened to set it to "3" or even "3 + 4", DAQFactory would convert the string into a number, 3 in both cases, since the string isn't evaluated, it is simply converted up to the first invalid character.

There are three ways around this:
1) use a different variable name
2) save, close and reload the doc
3) do:


which will erase all global variables and thus require redeclaration of all your globals.

Note that this behavior is a symptom of DAQFactory being a dynamic language that allows changes on the fly, and certain optimizations that go with it.  A compiled language of course would not have this issue.  That all said, I will admit that this one catches me rather often as I often forget to include the "string" in my declarations :)


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.