i am having trouble writing a program that i have to reuse the same input box and give a average of the numbers does anyone know how to retain each value so i can average them.
thank you for any help!!
Printable View
i am having trouble writing a program that i have to reuse the same input box and give a average of the numbers does anyone know how to retain each value so i can average them.
thank you for any help!!
I'm not sure I understand what you are trying to do? Why not add more textboxes divide by that number?
vb Code:
Private Sub Command1_Click() Dim num1 As Currency Dim num2 As Currency 'Store the value in memory num1 = Text1.Text num2 = Text2.Text 'Change the "2" to the number of textboxes you are using MsgBox ((num1 + num2) / 2) End Sub
Thread moved from the 'CodeBank VB6' forum (which is for you to post your code examples, not questions) to the 'VB6' forum
(thanks for letting us know Nightwalker83 + LaVolpe :thumb: )
Welcome to the forums.... :wave:
Here's a simple example:
...:wave:Code:Private Sub Command1_Click()
Dim Total As Long, Counter As Long
Dim Average As Single
Dim Temp As String
Do
Temp = InputBox("Enter number:") '~~> Show inputbox
If Temp <> vbNullString Then '~~> Check if the user has not used the Cancel button
Total = Total + Val(Temp) '~~> Add the value entered to the Total
Counter = Counter + 1 '~~> Increment the counter
End If
Loop Until Temp = vbNullString '~~> Loop this until the user had used the Cancel button
Average = (Total / Counter) '~~> Calculate average
MsgBox "Total=" & Total & " ; Total no. of values entered=" & Counter & " ; Average=" & Average
End Sub