04-01-2015 10:14 AM
I am using VB.NET and wondered if the Range fills property in a Meter can be changed programtically.
Solved! Go to Solution.
04-02-2015 08:27 AM
Hi Javier,
Yes you can change the Range Fills property programmatically. For one method you can look at example ScaleRangeFills, which should be located here: C:\Users\Public\Documents\National Instruments\MStudioVS2012\DotNET\Examples\UI\WindowsForms\NumericPointer\ScaleRangeFills
I believe this example shows how you can grab the property at run-time and change it from the UI.
If you just want to change it within the code, here is an example of using a button to change the range, range fill, and color of the range fill:
C#:
private void button1_Click(object sender, EventArgs e)
{ScaleRangeFill myFill = meter1.RangeFills[0];
myFill.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Yellow);
myFill.Range = new Range(2, 4);}
VB:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myFill As ScaleRangeFill = Meter1.RangeFills(0)
myFill.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Yellow)
myFill.Range = New Range(2, 4)
04-02-2015 12:48 PM
I wrote the code according to your example, but I a getting an error. "Index was out of range. Must be non-negative and less than the size of the collection" on the first declaration: Dim MeterFill_0 As ScaleRangeFill = Meter.RangeFills(0)
I have the three range fills in th GUI, please see attach JPG
Here is the funtioon I wrote.
Function FillMeter()
Dim MeterFill_0 As ScaleRangeFill = Meter.RangeFills(0)
Dim MeterFill_1 As ScaleRangeFill = Meter.RangeFills(1)
Dim MeterFill_2 As ScaleRangeFill = Meter.RangeFills(2)
If RadioButton_95541.Checked = True Then
'8.7 ft-lb at 4% variance is .348 ft-lb
MeterFill_0.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Yellow)
MeterFill_0.Range = New Range(0, 8.411)
MeterFill_1.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Green)
MeterFill_1.Range = New Range(8.412, 9.048)
MeterFill_2.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Red)
MeterFill_2.Range = New Range(9.049, 20)
Meter.Range = New Range(0, 20)
ElseIf RadioButton_95501.Checked = True Then
'16 ft-lb at 4% variance is .64 ft-lb
MeterFill_0.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Yellow)
MeterFill_0.Range = New Range(0, 15.35)
MeterFill_1.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Green)
MeterFill_1.Range = New Range(15.36, 16.64)
MeterFill_2.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Red)
MeterFill_2.Range = New Range(16.65, 25)
Meter.Range = New Range(0, 25)
ElseIf RadioButton_95511.Checked = True Then
'31 ft-lb at 4% variance is .64 ft-lb
MeterFill_0.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Yellow)
MeterFill_0.Range = New Range(0, 29.75)
MeterFill_1.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Green)
MeterFill_1.Range = New Range(29.76, 32.24)
MeterFill_2.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Red)
MeterFill_2.Range = New Range(32.25, 40)
Meter.Range = New Range(0, 40)
ElseIf RadioButton_95520.Checked = True Then
'80 ft-lb at 4% variance is 3.2 ft-lb
MeterFill_0.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Yellow)
MeterFill_0.Range = New Range(0, 76.79)
MeterFill_1.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Green)
MeterFill_1.Range = New Range(76.8, 83.2)
MeterFill_2.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Red)
MeterFill_2.Range = New Range(83.21, 100)
Meter.Range = New Range(0, 100)
ElseIf RadioButton_95525.Checked = True Then
'94 ft-lb at 4% variance is 3.76 ft-lb
MeterFill_0.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Yellow)
MeterFill_0.Range = New Range(0, 90.23)
MeterFill_1.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Green)
MeterFill_1.Range = New Range(90.24, 97.76)
MeterFill_2.Style = ScaleRangeFillStyle.CreateSolidStyle(Color.Red)
MeterFill_2.Range = New Range(97.77, 110)
Meter.Range = New Range(0, 110)
End If
Return 0
End Function
04-03-2015 02:20 PM
Hi Javier,
So it looks like you might be getting that error because your code is happening before the initialization of the component.
You will probably need to place the code after something like this so the initialization happens first:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
04-03-2015 03:32 PM
That gave me the clue I need to get it working. I was calling the function inside the form_Load, but because I was calling the function when radio button was changed sub was called, it was loading prior of initialization. I change the sub to radio button click and that worked.