Button using action "set to" and evaluate expression


Recommended Posts

I have a channel CB_Tank_X which I wish to update using the set to Action

if I use CB_Tank_X[0] in the expression it works

however if I use 

evaluate(Sites[Site_ID[0]]+"_Tank_X")[0]

it does not

the above expression evaluates to CB_Tank_X[0] so I was assuming the data would update

What is the correct syntax to get this to work by using evaluate

Rodney

 

Link to comment
Share on other sites

You cannot use evaluate() on the left side of an assignment (=).  In fact, you can't use any function on the left side of an =.  This is true in any programming language:

sin(3) = 4

does not make sense.  You can't assign the value 4 to the sin() of 3.

To do what you want, you have to use execute() and you have to do it from a quick sequence, since the Set To action just does a straight assignment.  The script would be something like:

private string datain = system.entryDialog("New value?")
if (!isempty(datain))
   execute(Sites[Site_ID[0]]+"_Tank_X = datain")
endif

 

 

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.