
Creating labels or other objects at runtime
The easiest way to create conrols at runtime is to create a control array.
for a label you would place it on a form,
give it a name(in this case Label1) and set it's Index property to 0 and
it's visible property to False. then do something like this:
Private Sub Command1_Click()
Dim i As Integer
Dim mystring(4) As String
mystring(0) = "These"
mystring(1) = "are"
mystring(2) = "dynamically"
mystring(3) = "loaded"
mystring(4) = "labels"
Label1(0).Caption = mystring(0)
Label1(0).Visible = True
For i = 1 To 4
Load Label1(i)
With Label1(i)
.Caption = mystring(i)
.Top = Label1(i - 1).Top + Label1(i - 1).Height + 5
.Left = Label1(i - 1).Left
.Visible = True
End With
Next i
End Sub
Note that you have to place the controls dynamically or else VB will place
all the controls on top of each other. Also make sure to make th control
visible.
Quote:
> I'm not very familiar with object oriented programming (although it's
> impossible not to be confronted with it these days), and I would like to
> know how I can create labels (or other objects) during runtime on my form,
> without placing them there first in designing the form.
> I understand I have to define (dim) them first, but how do I create them
in
> my code?