VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find the average of up to 500 numbers using an array

by Brandon (46 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 20th March 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Find the average of up to 500 numbers using an array

API Declarations


Private GetFlag As Boolean


Rate Find the average of up to 500 numbers using an array



'just keep the default names.

Private Sub Command1_Click()
    Call Average(GetFlag)
End Sub

Private Sub Form_Load()
Text1.Visible = False
End Sub

Public Function Average(Flag As Boolean)
Dim Count As Integer
Dim Continue As Integer
Dim X(1 To 500) As Integer
Flag = True 'initialize
Counter = 1
Total = 0
Do Until Not Flag
    X(Counter) = InputBox("Enter number" & Counter, "Enter number")
    Continue = MsgBox("Do you wish to enter more numbers?",vbYesNo, "Continue?")
    Total = Total + X(Counter)
    Counter = Counter + 1
    Select Case Continue
        Case vbYes
            Flag = True
        Case vbNo
            Flag = False
    End Select
Loop
Average = Total / (Counter - 1)  'subtract one due to
Text1.Visible = True             'initlizing at 1.
Text1.Text = Average 'print
End Function




Download this snippet    Add to My Saved Code

Find the average of up to 500 numbers using an array Comments

No comments have been posted about Find the average of up to 500 numbers using an array. Why not be the first to post a comment about Find the average of up to 500 numbers using an array.

Post your comment

Subject:
Message:
0/1000 characters