0

How To Read & Write ValueBox Values To/From Script

I need to read and write values to/from ValueBox controls using results from within a script.

I tried pasting the simple example from the help tutorials/examples but I receive an error. I then tried the following without success:

float valueBox1Value = ValueBox1.Value?.Value;

I was able to write the value to a Labelx.Text after converting to text but I have exhausted options trying to write to a ValeuBox

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • I know you said ValueBox but in case it would help, I think this is the syntax for Text Boxes:

    TextBox2.Text=TextBox1.Text;

    I'm not sure on ValueBoxes right off. I guess I haven't had a need to do that since in my case at least, I've only used value boxes that were set to display the value of a sourcetag or I've used the calculation option within the value box setup if I wanted to do something like take the value from a tag in one valuebox and do something with it. 

    The Canary Team might have better advice here but perhaps an example of what you are looking to do would also help.

    Like
      • Derwyn Oxley
      • System Integrator
      • derwyn
      • 1 yr ago
      • Reported - view

      James Wise Many thanks for your reply. I am trying to do some calculations in a script which have a mix of text entry, then converted to a float number. This works and I can convert to string and display the result in a textbox or label. I could live with this for now (display a number as a string) but only if I can read another number which is the result of a calculation in a ValueBox. If I could read that value into the script, run the 2nd part of the calc and display the result, again as a string, it could work.

      I can read and write strings to Labels and TextBoxes but don't seem to be able to do the same with numbers!!?? I'm hoping it's just a syntax - the examples in the help popup suggest it's real simple (FLW :))

      The example shows:

      object valueBox2Value = valueBox2.Value?.Value;
      if (valueBox2Value == 1)
          button3.Text = "Hello";
      else if (valueBox2Value == 0)
          button4.Text = "Goodbye";
      
      But when I run this, I get an Object vs int error. So I tried using float vs object
      in the var declaration
      
      
      Like
    • Derwyn Oxley Could you post your script and provide a detailed explanation of the desired outcome? The more info, the better 🙂.

      Like
      • Derwyn Oxley
      • System Integrator
      • derwyn
      • 1 yr ago
      • Reported - view

      Steve Mason 

       

       

      I am logging run time values from devices in the field. I have a screen in Axiom with 2 x Datetime pickers (start time and end time). I use these values to extract the runtime values of the device for start time and end time. Using a ValueBox with calc, I can now show the hours run for the device over the selected period = result.

      What I am now trying to do is display the device run hours (drh) for the device as a percentage of the hours selected. I first need to calculate what the total hours are which I have managed to do in the script (period selected - ps). I can show this as a string but not as a number. I now need the device run hours back in the script so I can do drh/ps*100. I'd also like to display as a number if possible. 

      Like
  • I definitely could have something off here but here's what I used recently to set the value of ValueBox1 to 100 via a script:

    string valueBoxName = "ValueBox1";

    ControlValueBox valueBox = Screen.ScreenControls[valueBoxName] as ControlValueBox;

    TVQ newValue = new TVQ(DateTime.Now, 100, 192);

    valueBox.Value = newValue;

    Like
print this pagePrint this page
Like Follow
  • 5 days agoLast active
  • 5Replies
  • 158Views
  • 4 Following