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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top