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 iAsInteger

CustomizeForm.Show()

stext = CustomizeForm.ComboBoxSText.SelectedItem

For i = 0To i = stext

Dim txtNameAsNew TextBox

txtName.Name ="TextBoxST" + i.ToString

Me.Controls.Add(txtName)

Next

thanks

Jane

[1630 byte] By [JaneSathyan] at [2007-12-24]
# 1

set the location for the text box. and visiable to true.

with txtName

.Top = <top postion>

.Left = <left position>

.Width = 24

.Height = 16

.Visible = True

end with

PrasantSwain at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

but it displays only one textbox... even i changed my code like this...

Dim stext As Integer

Dim i As Integer

Dim incre As Integer = 100

stext = CustomizeForm.ComboBoxSText.SelectedItem

For i = 0 To i >= stext

Dim txtName As New TextBox

txtName.Name = "TextBoxST" + i.ToString

incre = incre + 70

txtName.Left = incre

txtName.Top = incre

txtName.Width = 124

txtName.Height = 20

MessageBox.Show(txtName.Name)

txtName.Visible = True

Me.Controls.Add(txtName)

i = i + 1

Next

JaneSathyan at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

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

.

spotty at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Thanks a lot... it worked great... thanks spotty
JaneSathyan at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...