generating textbox at runtime.....
Hi,
i need to generate some text box at runtime and also during the form load... it gets a number from previous form is got and generates that number of textboxs...
i tryed this code in form load... it's not showing any exception or error.. and its also not showing the textboxes.
Dim stextAsInteger
Dim iAsIntegerCustomizeForm.Show()
stext = CustomizeForm.ComboBoxSText.SelectedItemFor i = 0To i = stextDim txtNameAsNew TextBoxtxtName.Name =
"TextBoxST" + i.ToStringMe.Controls.Add(txtName)Nextthanks
Jane
Your problem is
For i = 0 To i >= stext
This should be something like
For i = 0 To Ctype(stext, Integer) -1
Reason
At present the line you are doing will
i >= stext will result in false which which is converted to 0
so you loop construct at the moment
For i = 0 To i >= stext
will loop from 0 to 0
and hence will only loop once.
Resolution
I assume that the stext is how many of the controls you wish to create so if you want to create 1 control - then stext would be 1 in which case the loop
For i = 0 To Ctype(stext, Integer) -1
will loop from 0 to (1-1) which is 0 and hence it will loop from 0 to 0 which is once.
if 2 is entered it will loop
will loop from 0 to (2-1) which is 1 and hence it will loop from 0 to 1 which is two
.