Results 1 to 4 of 4

Thread: adding input boxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    1

    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!!

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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:
    1. Private Sub Command1_Click()
    2. Dim num1 As Currency
    3. Dim num2 As Currency
    4. 'Store the value in memory
    5. num1 = Text1.Text
    6. num2 = Text2.Text
    7. 'Change the "2" to the number of textboxes you are using  
    8. MsgBox ((num1 + num2) / 2)
    9. 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

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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 )

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: adding input boxes

    Welcome to the forums....

    Quote Originally Posted by shaggy7851 View Post
    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
  •  



Click Here to Expand Forum to Full Width