convert variable value using user entered data


Recommended Posts

I have a variable value component that displays a channel's value (input register). I set the variable value component's units to Volts. What I want to accomplish is have an edit box where a user can enter a numeric value (in this case it would be a resistance value) and I want to read that value and use it to update the Variable value to it's new converted value with the units changed as well (Amps). 

1. Variable value component (V)

example: 12.00 V

2. User enters numeric data (ohms) into edit box

read entered data

calculate new variable value ( I = V/R)

example: user enters 100 ohms; calculate 12/100 = 0.12

3. update variable value component to display new converted value (A)

example: 12.00 V ---> 0.12 A


Hopefully this makes sense and I would think it would be something simple to accomplish but I just can't figure it out yet.

Link to comment
Share on other sites

OK, first just to be clear the "Units" field in the variable value component is just a label.

To do what you want you need a global variable to hold the ohms.  So:

1) create a new Sequence.  Call it "StartUp" and check the box "Auto-Start" at the top so it runs on boot.  The script would be simply:

global ohms = 1

2) Apply then run the sequence

3) create a new variable value component. Select the "Analog Out" button under Quick in its properties and enter Ohms.  Feel free to edit the caption and units afterwards. This will display the ohms value and when you click on the variable value control it will prompt for a new value

4) create another variable value component, Caption of "Amps".  Expression will be:  "volts / ohms" (without the quotes) where volts is the name of the channel holding your volts.  Ohms is that global variable we created.

Link to comment
Share on other sites

Thanks! this can work.

One thing that I didn't mention was that if the user does not enter resistance data I would still want to display the voltage value of the channel. So using your example I now have 3 variable value components rather than 2. is it possible to have the one switch from Volts to Amps?

Thank you again!

Link to comment
Share on other sites

That would make the value change to volts but the units label does not change from Amps to Volts that's more what i would want to do. i guess if they enter 1 as the ohms (or default as 1) the units will show as volts but when they put a value other than 1 I would want it to change to Amps.

Link to comment
Share on other sites

There are lots of ways to do this.  The easiest is to create two variable value controls, one showing amps and one showing volts.  Then set the Visibile expression to ohms == 1 for the one that displays volts, and ohms != 1 for the one that displays amps.  This will cause DAQFactory to only display one or the other.  The Visible expression is on the Size tab of the component's properties.

Link to comment
Share on other sites

oh ok cool. I'm trying to keep them at the same x,y postions so i will have 1 variable value component (A) on top of the other (V). do you recommend I do it this way? only reason is because i'm limited in space. When in edit mode is there a way to make the invisible components appear (in case if i forget they're invisible in the future)? I really appreciate all the help you've given

Link to comment
Share on other sites

  • 2 weeks later...

Yes, you can just put them on top of each other.  There is no built in way to make them visible.  You can, of course, just create a global variable called, say "showAllComponents" and then change your visible expressions to:

(ohms == 1) || showAllComponents


(ohms != 1) || showAllComponents

Then set showAllComponents to 0 for normal operation, and 1 to show everything.

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.