How do you find greatest number among 5 with vb.net?

find, max, vb.net

Solution

As David suggested, keep your values in a list. That's easier than using individual variables and can be extended to as many values as requested (up to millions of values).

If you need to keep individual variables for some reason, do this:

Dim max As Integer = a
Dim name As String = "A"
If b > max Then
    max = b
    name = "B"
End If
If c > max Then
    max = c
    name = "C"
End If
If d > max Then
    max = d
    name = "D"
End If
' ...  extend to as many variables as you need.
MsgBox(name & " is greater")

Problem

This is code for finding maximum in 3 but i want the code for finding maximum amoung 5: ``` Dim a, b, c As Integer a = InputBox("enter 1st no.") b = InputBox("enter 2nd no.") c = InputBox("enter 3rd no.") If a > b Then If a > c Then MsgBox("A is Greater") Else MsgBox("C is greater") End If Else If b > c Then MsgBox("B is Greater") Else MsgBox("C is Greater") End If End If ```

Original source