By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

Create Text Boxes at Run Time in VB.6

P: 4
Hi,

Can any help to create textboxes in VB.06 on run time.

please provide the code if anybody have.

Thanks in advance
Anuarg Jain
Dec 20 '07 #1
Share this Question
Share on Google+
3 Replies


P: 3
Code For VB6
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim controlname As String
  3.     For i = 1 To 6  '   Change
  4.         controlname = "txtControl" & CStr((i))
  5.         Call Controls.Add("VB.TextBox", controlname, Me)
  6.         With Controls(controlname)
  7.             .Left = 56 ' Change
  8.             .Top = (i - 1) * 480 ' Change
  9.             .Visible = True
  10.         End With
  11.     Next i
  12. End Sub
  13.  
That should work - just modify as needed

Edit : Hold On - VB.06 - Do you mean VB 6.0?
Dec 20 '07 #2

Expert 5K+
P: 8,434
Of course, the simpler technique is to create a textbox at design time, set the Index property to 0 to make it a control array, then just use the Load statement to add new ones at run time. This makes them more convenient to work with, too.
Dec 20 '07 #3

vdraceil
100+
P: 236
Killer's advice is the best to create run time controls.
If you want the code, look below.

Create a textbox named text1(0) to begin a control array

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2.  
  3. Private Sub Command1_Click()
  4.   Load text1(i+1)
  5.   ' You may align the new control with its top & left properties
  6.   text1(i + 1).Top = text1(i).Top + text1(i).Width + 15
  7.   text1(i + 1).Left = text1(i).Left
  8.   i = i + 1
  9. End Sub
All the best
Dec 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.