Finiding Maximum Value on an Array

This code will show you how your going to find and display the maximum value in your array.

The Code:
'You will need a FORM and a command button

Option Explicit
Dim A(20), num, i, j, max As Integer

Private Sub Command1_Click()
Print "Your array contains:"
For i = 0 To num - 1
Print A(i)
Next i
Print "Maximum Value= "; max
End Sub
Private Sub Form_Load()
num = InputBox("Initialize your array [1-20]:")

For i = 0 To num - 1
A(i) = InputBox("Enter your array:")
Next i

'find maximum
max = A(0)
For i = 0 To num - 1
If max < A(i) Then
max = A(i)
End If
End Sub


Post a Comment