Finding Maximum Value

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

'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
Next
End Sub

0 comments:

Post a Comment