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

ElseIf IsNumeric(iNumber = 2) Then
Is iNumber always 2? The first time it is 1.

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
commented: Yes, of course. +15

Thank you very much Reverend Jim, it works

Be a part of the DaniWeb community

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