Hi! everyone.
i have never learn to loop an groupbox or anything so i don't know what wrong but the compiler said "NullReferenceException was unhandle" and here is my code. Please help!

iNumberOfPassengers = CInt(txtAdult.Text) 
        gboPassengerDetails.Hide()

        Dim gboNextPassenger(iNumberOfPassengers) As GroupBox
 For iCounter As Integer = 2 To iNumberOfPassengers

            gboNextPassenger(iCounter) = New GroupBox


        Next

        With gboNextPassenger(iCounter)
            .Text = "Passenger Details - Adult number " & iCounter + 1.ToString
            .Visible = True
            .Left = 31
            .Top = 348
            .Size = New Size(651, 236)
        End With

You are starting your counter at 2.
...which means you are expecting your number of passengers to be greater than 2 and also the size of your array gboNextPassenger to be at least >> 3 <<

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.