Click to See Complete Forum and Search --> : How to create textbox at run time


vipulsk
January 29th, 2000, 11:05 AM
I Need to create TextBox at run time ,kindly guide me how can I do that.I need user to input how many names he want to enter if he inputs 10 and OK 10 textbox i need to display if 50 than 50 so kindly guide me.Thanking u in anticipation ,
Vipul

Starcraft
January 29th, 2000, 12:02 PM
just put those 50 textboxes already on the form, but set their visiblility to false, and then when you want those 50 to show set the visibility to true.

chem1
January 29th, 2000, 12:45 PM
Use the following.This code adds menus at runtime .U can try to add text boxes.If not then tell me I willsne u code that

option Explicit

Dim gClick as Integer 'Variable to moniotor Clicks
private Sub mnuOpen_Click()
on error GoTo MyError

CommonDialog1.CancelError = true 'Catch the Cancel Button
gClick = gClick + 1 'set gClick to 1

'Show the CommonDialog Open BOx
CommonDialog1.ShowOpen

'Load the first Menu
Load mnuLatestFile(gClick + 1)

'set the visible property to true
mnuLatestFile(gClick + 1).Visible = true

'Change the caption to the file that the user selected
mnuLatestFile(gClick + 1).Caption = CommonDialog1.FileName
Exit Sub

MyError:
Exit Sub
End Sub

Chris Eastwood
January 30th, 2000, 05:01 AM
Here's one way that works with VB 4, 5 and 6 :


Create a form (FORM1) with a textbox (Text1) and a command button (Command1). Set the 'Index' property of Text1 to '0' and paste in the following code :


option Explicit
'
private Sub Command1_Click()
Dim l as Long
Dim sVal as string
'
sVal = InputBox("How many textboxes ?")
'
If sVal = "" then Exit Sub
'
l = CLng(sVal)
'
CreateTextBoxes l
'
End Sub
'
private Sub CreateTextBoxes(byval l as Long)
'
Dim lCount as Long
'
for lCount = 1 to l
'
Load Text1(lCount)
With Text1(lCount)
.Top = Text1(lCount - 1).Top + Text1(lCount - 1).Height + 25
.Width = Text1(lCount - 1).Width
.Left = Text1(lCount - 1).Left
.Visible = true
End With
next
'
End Sub




The program will create the specified number of textboxes underneath the existing one (change the positioning in the CreateTextBoxes routine). When you want to handle events for each textbox, you'll need to remember to check the 'Index' property for each one (if relevant).



Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

January 30th, 2000, 07:53 AM
Why waste system resources loading 50 textboxes, when you can create them at run-time. Using a control array, put a textbox on the form with the index 0, then in your code when you need a new one just use Load textbox_name(new_index). Just make sure you control the index_number or you will end up with bogus boxes.

Cimperiali
December 20th, 2001, 01:58 AM
;-)
'
'


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater