Averaging the values in Textboxes

T

theroundpen

I have created a small form with 10 textbox objects from the "Control
Toolbox" that will receive a value of 1 through 5 by the user. In the 11th
textbox I want to calculate the average of the 10 values. Can someone please
show me the code for getting this accomplished?

Thank you very much!
 
G

Greg Maxey

I have created a small form with 10 textbox objects from the "Control
Toolbox" that will receive a value of 1 through 5 by the user.  In the 11th
textbox I want to calculate the average of the 10 values.  Can someone please
show me the code for getting this accomplished?

Thank you very much!

You could use something like this which you would need to adapt for 10
text fields.:

Private Sub TextBox1_Change()
DoCalc
End Sub
Private Sub TextBox2_Change()
DoCalc
End Sub
Private Sub TextBox3_Change()
DoCalc
End Sub


Sub DoCalc()
Me.TextBox4.Value = (Val(Me.TextBox1.Value) + Val(Me.TextBox2.Value) +
Val(Me.TextBox3.Value)) / 3
End Sub
 
T

theroundpen

This was exactly what I needed - THANK YOU!!!!

Greg Maxey said:
You could use something like this which you would need to adapt for 10
text fields.:

Private Sub TextBox1_Change()
DoCalc
End Sub
Private Sub TextBox2_Change()
DoCalc
End Sub
Private Sub TextBox3_Change()
DoCalc
End Sub


Sub DoCalc()
Me.TextBox4.Value = (Val(Me.TextBox1.Value) + Val(Me.TextBox2.Value) +
Val(Me.TextBox3.Value)) / 3
End Sub
 
Top