Hi there
I'm creating an invoice generator program, first the user must enter the number of products to diplay on a pdf file, below are my codes.
My proble is, this if statement does not run as expected

 Private Sub Add_New_Order_Item_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim sNumber As String
        Dim iNumber As Integer

        sNumber = InputBox("Enter a number", "Numbers Only", iNumber)
        If IsNumeric(iNumber = 1) Then
            GroupBox1.Visible = True

        ElseIf IsNumeric(iNumber = 2) Then
            GroupBox1.Visible = True
            GroupBox2.Visible = True
        ElseIf IsNumeric(iNumber = 2) Then
            GroupBox1.Visible = True
            GroupBox2.Visible = True
            GroupBox3.Visible = True

        ElseIf IsNumeric(iNumber = 2) Then
            GroupBox1.Visible = True
            GroupBox2.Visible = True
            GroupBox3.Visible = True
            GroupBox4.Visible = True

        ElseIf IsNumeric(iNumber = 2) Then
            GroupBox1.Visible = True
            GroupBox2.Visible = True
            GroupBox3.Visible = True
            GroupBox4.Visible = True
            GroupBox5.Visible = True
        else
        msgbox("Enter only numbers from 1 to 5")
        End If

    End Sub

When used as a single statement

iNumber = 1

assigns 1 to iNumber. When used as a conditional it evaluates to a Boolean which is actually 0 or -1 so

If IsNumeric(iNumber = 1) Then

will always evaluate to True no matter what number you compare iNumber to. One alternative is

Dim iNumber As Integer = 1
Dim sNumber As String = InputBox("Enter a number", "Numbers Only", iNumber)

If IsNumeric(sNumber) Then

    iNumber = CInt(sNumber)

    If iNumber >= 1 And iNumber <= 5 Then

        For i As Integer = 1 To iNumber
            Me.Controls("GroupBox" & i).Visible = True
        Next

    Else
        MsgBox("Enter only numbers from 1 to 5")
    End If
Else
    MsgBox("Enter only numbers from 1 to 5")
End If

Edited 1 Year Ago by Reverend Jim

Comments
Yes, of course.
This question has already been answered. Start a new discussion instead.