FTView SE - get current value of numeric entry field

ASF

Lifetime Supporting Member
Join Date
Jun 2012
Location
Australia
Posts
3,921
Hi all,

I'm trying to change the colour of some text based on whether an input the user has typed is between two (min and max) values. I have a numeric entry field, and once a valid value is present, the text will go from red to green.

For example, let's say the min and max values are 50 and 100. Initially, the value of the numeric display is 0, so the text is red. The operator types "7" - still red. The operator types "5" - the value in the entry field is now 75, so the text goes green. The operator types "0" - the value is now 750, so the text goes back to red.

As the numeric entry field doesn't actually send the value to the tag until you download it, I can't just monitor the value connection of the numeric entry object. I figure I'll probably have to do something with VBA - when the value changes, check it against the two relevant tags - but I can't figure out how to address the real-time value of my numeric entry field.

Any ideas?
 
If you use KeyUp event to monitor the numeric field, you can read the value before is downloaded. However, the numeric fields have their own background color behavior and background color attribute is not public (if you right click on any numeric field you'll see that color and fill attributes are disabled).

Trying to bypass this issue, I did a little test with a polygon and a numeric field:

Code:
Private Sub NumericInput1_KeyUp(ByVal KeyCode As Integer, ByVal Shift As Integer)
    If (NumericInput1.Value < 50) Or (NumericInput1.Value > 100) Then
        Me.Polygon1.BackColor = RGB(255, 0, 0)
    Else
        Me.Polygon1.BackColor = RGB(0, 255, 0)
    End If
End Sub
I was thinking of putting the polygon behind the numeric field but... there's no way to make transparent the numeric field background.

Returning to the original behavior of the numeric field (red background when you try to download a value outside the min and max range), I use the tooltip feature to give a hint about the valid range.
 
Thanks, I'll give that code a try. I'm building my own keypad, so I'm using touch animation on rectangles to issue a "SendKeys" command - not sure if that will trigger the "KeyUp", but I'll find out...otherwise, perhaps I could use NumericInput1_Change to trigger the code?

FWIW I'm not trying to make the numeric input itself change colour - just some text above it. So your example changing the polygon colour will translate almost exactly to what I'm doing.

Thanks!
 
Okay, so I've got it as far as changing the colour when it's within or not within hardcoded values. Next, I tried to use variables instead of fixed values. To keep it simple, I put two numeric displays on the screen, and tied them to those two values. They display the min and max values correctly, and are exposed to VBA (VBA Control). Then I changed your code to:
Code:
Private Sub NumericInput1_KeyUp(ByVal KeyCode As Integer, ByVal Shift As Integer)
    If (NumericInput1.Value < Me.NumericDisplay1.Value) Or (NumericInput1.Value > Me.NumericDisplay2.Value) Then
        Me.Polygon1.BackColor = RGB(255, 0, 0)
    Else
        Me.Polygon1.BackColor = RGB(0, 255, 0)
    End If
End Sub

It doesn't work. The polygon just stays red.

I'd ideally like to tie it directly to the two tags, rather than reading the numeric displays, but that's problematic as the tags are passed into the display using the /T flag when it's opened, and I haven't found a way to address tags in that manner with VBA.
 
Well, I solved it by assigning the values to a local variable. This is my finished code:

Code:
Dim MinValue As Single
Dim MaxValue As Single

Private Sub Value_Data_KeyUp(ByVal KeyCode As Integer, ByVal Shift As Integer)
    MinValue = Min.Value
    MaxValue = Max.Value
    If (Value_Data.Value < MinValue) Or (Value_Data.Value > MaxValue) Then
        Me.Text_MinMax.ForeColor = RGB(255, 0, 0)
    Else
        Me.Text_MinMax.ForeColor = RGB(0, 255, 0)
    End If
    
End Sub

I thought that it might be a good idea to point the MinValue and MaxValue variables to the numeric display fields on DisplayAnimationStart, instead of every time a button is pressed, but it turns out if I do that I get a compile error. I guess before the animation starts there is no data in the numeric display yet.

Anyhow, thanks!
 
Your first code didn't work because NumericDisplay.Value returns a variant. It's possible to solve that issue using a conversion method like:
Code:
CInt(NumericDisplay1.Value)
Have you considered using parameters to pass information to your keypad?
 
Aha, that makes sense! One note though - the value may not always be an integer, many times it's a floating point. What command would I use to convert to floating point (or "single", as VBA has it)?

I'll try it out...simple code is the best code!

If I use a parameter file, that's going to mean a whole lot of parameter files. There are hundreds of places where I will use this keypad. And I'm only passing three tags - a min, max and the entered value - so it seems a bit overkill to go to the extent of a parameter file when I can just pass tags directly using /T. Plus, after playing around with it a bit further, I think monitoring tags rather than just the value of an invisible numeric display only makes it more complicated...
 
I should know better than to ask simple questions before googling...
Code:
CSng(NumericDisplay1.Value)

Works a treat! Thanks for the help nhatsen!
 

Similar Topics

When I test run an application I made, the "current value" column in the RecipePlus table comes up empty (picture attached). Does this have to do...
Replies
1
Views
1,618
Hello Folks! I have an issue and its very often but in this case i applied all the tricks and tips that i always do in similiar issues but in this...
Replies
2
Views
776
Hi All, Everytime I try to call the current object in FTview, I need use the coding below to call the property of the current active object...
Replies
0
Views
2,495
Hi , in my application i was supposed to read the recipe name in a string & have to display it all other screens of scada & to perform operation...
Replies
0
Views
2,901
I am creating a global object in FTView SE 13. I want to have a string read from the PLC and display (in this case the tagname). So lets say...
Replies
4
Views
167
Back
Top Bottom