|
-
Mar 6th, 2010, 07:15 PM
#1
Thread Starter
New Member
adding input boxes
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!!
-
Mar 6th, 2010, 10:06 PM
#2
Re: adding input boxes
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
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 7th, 2010, 08:21 AM
#3
Re: adding input boxes
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 )
-
Mar 7th, 2010, 08:45 AM
#4
Re: adding input boxes
Welcome to the forums.... 
 Originally Posted by shaggy7851
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!!
Here's a simple example:
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
...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|