
Creating new text boxes at run time
Create a text box array by adding one to a form and setting its index
property to 0. Then just use:
Private Sub Command1_Click()
Dim x As Integer
For x = 0 To 9
If x > 0 Then Load Text1(x)
Text1(x).Text = "field" & CStr(x)
Text1(x).Left = 300
Text1(x).Top = 360 * x
Text1(x).Visible = True
' ...
' Do other stuff here...
' ...
Next x
End Sub
Note that you can not assign a value to the Name property at runtime.
--
Randy Birch, MVP Visual Basic
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/
Please correspond only using the newsgroups so all can benefit.
Is it possible to create and display new textbox controls (or other controls
for that matter) on a regular VB form at run time?
I had hoped to do something like this:
Private Sub Form_Load()
Dim txt As TextBox
Dim i As Integer
For i = 1 To 10
Set txt = new TextBox
txt.name = "field" & CStr(i)
...
Do other stuff here...
...
Next i
End Sub
This doesn't work because although it is possible to dimension a variable as
a TextBox, the line "Set txt = New TextBox" is not valid. 'TextBox' doesn't
show up in the code completion list.
So is it at all possible to create new textbox controls on my form at
run-time? If so, am I at all close with my example above? Or is there some
other way to do this?
Please advise.
Thanks!
--
Tom Castiglia
Hershey Technologies
www.hersheytech.com
(858) 458-4222 x18