Creat form in a Do loop error

Muchni

Member
Joined
Sep 30, 2008
Messages
18
Programming Experience
1-3
Hi I want to creat new form in a loop in vb.net 2008 and I wrote like this but it wont work, the do loop is correct but the line where I "create" the form its an error, help please.

VB.NET:
Expand Collapse Copy
Public Class Form1
    Dim a(b) As Form
    Dim b As Integer = 0
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        a(b) = New Form
        Do Until b >= 10
            a(b)
            a(b).Show()
            b += 1
        Loop


    End Sub
End Class
 
Last edited:
VB.NET:
Expand Collapse Copy
Dim a(10) As Form
    Dim b As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Do Until b >= 10
            a(b) = New Form
            a(b).Show()
            b += 1
        Loop

    End Sub

However, why in the name of frick on a stick you'd want to do this is beyond me. Unless you are trying to create a problematic program?
 
I agree with Vis about not needing to open this many forms, but for the sake of learning loops I will show a couple examples.

VB.NET:
Expand Collapse Copy
        'For Next Loop
        For intFormCount As Integer = 1 To 10
            Dim frm As New Form
            frm.Text = "For Next Loop - Form " & intFormCount.ToString
            frm.Show()
        Next intFormCount 

        'Do Loop
        Dim intCounter As Integer = 0

        Do Until intCounter >= 10
            intCounter += 1

            Dim frm As New Form
            frm.Text = "Do Until Loop - Form " & intCounter.ToString
            frm.Show()
        Loop
 
Back
Top