this is my code

``````Private Sub Command1_Click()
Dim maximum, minimum, highest, lowest As Integer
Dim num(1 To 5), i, j, z As Integer

For i = 1 To 5
num(i) = InputBox("number")
Next i

highest = num(1)
lowest = num(1)

For z = 1 To 5
If num(z) > highest Then
highest = num(z)
End If
Next z

For j = 1 To 5
If num(j) < lowest Then
lowest = num(j)
End If
Next j

Print "Highest is : "; highest
Print "Lowest is : "; lowest

End Sub``````

whenever i enter numbers in the input box with this sequence : 4, 4, 44, 4, 5
the result of the highest number will be 5
same if i enter in this sequence : 4, 44, 4, 5 or 5, 5, 55, 6
anybody can help??

## All 2 Replies

Hi,

you are declared `Dim num(1 To 5), i, j, z As Integer` here z only the integer, but i, j and num are considered as Variant.
In the input

For i = 1 To 5
num(i) = InputBox("number")
Next i

You are getting the string value (such as "4", "4", "44", "4", "5"). You did not convert it into integer. so vb do the string comparison. that is why "5" is greater than "44"

you have to change your code as

``````Private Sub Command1_Click()
Dim maximum, minimum, highest, lowest As Integer
Dim num(1 To 5) as Integer, i as Integer, j As Integer, z As Integer

For i = 1 To 5
num(i) = Val(InputBox("number"))
Next i

highest = num(1)
lowest = num(1)
'..... Rest of the codes``````

thanks for the explanation! it helps alot. thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.