# Two NumericUpDown - average value

Page 1 of 1

## 3 Replies - 345 Views - Last Post: 26 April 2019 - 06:18 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=415881&amp;s=54eaf09b9365edc1e5721b635a20b7cf&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 VeX85

Reputation: 1
• Posts: 4
• Joined: 15-March 19

# Two NumericUpDown - average value

Posted 25 April 2019 - 04:02 AM

Hi,
I need help, how I can calculate the average value of two NumericUPDown and show it in Label ?

```Public Class mail_premia
Dim fPreviousValue As Single = 0

With NumericUpDown1
.DecimalPlaces = 1
.Increment = 0.5
.Maximum = 20
.Minimum = 0
fPreviousValue = .Value
End With
With NumericUpDown2
.DecimalPlaces = 1
.Increment = 0.5
.Maximum = 20
.Minimum = 0
fPreviousValue = .Value
End With
End Sub

Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles Label1.TextChanged

'here the average value

End Sub
End Class

```

Is This A Good Question/Topic? 0

## Replies To: Two NumericUpDown - average value

### #2 CharlieMay

• This space intentionally left blank

Reputation: 1733
• Posts: 5,710
• Joined: 25-September 09

## Re: Two NumericUpDown - average value

Posted 25 April 2019 - 05:27 AM

You should be able to perform the math against the value of each selected number in the NUD boxes and divide by the number of boxes involved. What are you trying to do with fPreviousValue?

I would also remove the sub you're showing and combine the handlers for the ValueChanged event of the NumericUpDown control. Then inside that set the label's .Text property to the calculated result. This way, as you change one or the other, the label will update with the new value.

This post has been edited by CharlieMay: 25 April 2019 - 05:30 AM

### #3 andrewsw

• quantum multiprover

Reputation: 6792
• Posts: 28,050
• Joined: 12-December 12

## Re: Two NumericUpDown - average value

Posted 25 April 2019 - 05:28 AM

Handles Label1.TextChanged This doesn't seem right.

In whichever event you will use you first need to read the two values from the controls, have you discovered how to read a value from a numericupdown?

### #4 VeX85

Reputation: 1
• Posts: 4
• Joined: 15-March 19

## Re: Two NumericUpDown - average value

Posted 26 April 2019 - 06:18 AM

fPreviousValue I needed to test the old code, it is unnecessary.

Thank you for your hints. Good code below.

```Public Class mail_premia
Dim a, b As Integer

With NumericUpDown1
.DecimalPlaces = 1
.Increment = 0.5
.Maximum = 20
.Minimum = 0
End With
With NumericUpDown2
.DecimalPlaces = 1
.Increment = 0.5
.Maximum = 20
.Minimum = 0
End With

End Sub

Private Sub Average(sender As System.Object, e As System.EventArgs)
Label1.Text = ((Val(a) + Val(B)/>) / 2)
End Sub

Private Sub NumericUpDown1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown1.ValueChanged
a = NumericUpDown1.Value
End Sub

Private Sub NumericUpDown2_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown2.ValueChanged
b = NumericUpDown2.Value
End Sub
End Class

```