Hi,

The code below creates 4 line controls at run-time.

The problem is, I want to create from only 1 to 4 of these controls at run-time (not always 4).


Does anybody have an idea how to do this? Thanks for any help.

Private Sub Form_Load()

Formdiagram.Controls.Add "VB.line", "Line1"
Formdiagram!line1.X1 = 2400
Formdiagram!line1.X2 = 2410
Formdiagram!line1.Y1 = 2400
Formdiagram!line1.Y2 = 2410
Formdiagram!line1.Visible = True
Formdiagram!line1.BorderColor = vbRed
Formdiagram!line1.BorderWidth = 6


Formdiagram.Controls.Add "VB.line", "Line2"
Formdiagram!line2.X1 = 2800
Formdiagram!line2.X2 = 2810
Formdiagram!line2.Y1 = 2800
Formdiagram!line2.Y2 = 2810
Formdiagram!line2.Visible = True
Formdiagram!line2.BorderColor = vbRed
Formdiagram!line2.BorderWidth = 6


Formdiagram.Controls.Add "VB.line", "Line3"
Formdiagram!line3.X1 = 1800
Formdiagram!line3.X2 = 1810
Formdiagram!line3.Y1 = 1800
Formdiagram!line3.Y2 = 1810
Formdiagram!line3.Visible = True
Formdiagram!line3.BorderColor = vbRed
Formdiagram!line3.BorderWidth = 6

Formdiagram.Controls.Add "VB.line", "Line4"
Formdiagram!line4.X1 = 1300
Formdiagram!line4.X2 = 1310
Formdiagram!line4.Y1 = 1300
Formdiagram!line4.Y2 = 1310
Formdiagram!line4.Visible = True
Formdiagram!line4.BorderColor = vbRed
Formdiagram!line4.BorderWidth = 6

End Sub