Variable history?


kedi

Recommended Posts

When I created a component to display a variable value, it initially displayed a whole row of the values of that variable incremented as in the sequence code. When specified MyVariable(0) in the component expression window, instead of just MyVariable, I then got just one, current instance of the variable value. Does every variable have a history generated? Can I force it to not have a history in the declaration of the variable?

I ask in relation to the wimpy little laptop that the code is running on. Less overhead would be nice.

Link to comment
Share on other sites

First, the correct syntax is MyVariable[0] and this is required if MyVariable is an array, otherwise the variable value control will display the first 20 values.  Variables won't generate history on their own if you use = to give them values.  So:

global x
x = 3
x = 2

does not generate an array with {2,3}.  It creates a variable called x, assigns 3 to it, then assigns 2 to it, overwriting the 3.  To create a history with a variable you have to use myVariable.addValue() on it.  That said, a history is just an array, and there are other ways you can make a variable an array, such as myVariable.append(), etc, along with direct assignment of a specified array (i.e. x = {3,2}), and direct setting of array elements (i.e. x[3] = 2). 

 

And of course if you do myVariable = myChannel and myChannel has a history, then myVariable will have a copy of that history.  A useful thing when you want to capture the current history before new data appears.  It works for subsets too:

myVariable = myChannel[0,99]

or

myVariable = myChannel[systime(), systime() - 60]

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.

Guest
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.