954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to insert new textbox, label during runtime vb

Anyone please give an idea on how to create text box & label control during run time... Anyone pls..

xirosen
Light Poster
30 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

plz check this.

Attachments Create_control_in_runtime.zip (2.07KB)
abu taher
Practically a Posting Shark
845 posts since Jul 2008
Reputation Points: 14
Solved Threads: 78
 

thanks a lot for the help......

xirosen
Light Poster
30 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Hi,
Please find the code below to create VB Controls/Array of Controls Dynamically

Dim ControlArrayCOunt As Integer
Dim txtControlArray() As TextBox
Private Sub Create_Control()
On Error GoTo a

Dim txtControl As TextBox
Set txtControl = Controls.Add("VB.TextBox", "txtControl")
txtControl.Top = 300
txtControl.Left = 200
txtControl.Visible = True
Exit Sub

a:


End Sub

Private Sub Create_ControlArray()
On Error GoTo a

ReDim txtControlArray(ControlArrayCOunt)

Set txtControlArray(ControlArrayCOunt - 1) = Controls.Add("VB.TextBox", "txtControl" & ControlArrayCOunt)
txtControlArray(ControlArrayCOunt - 1).Text = "TextBox" & ControlArrayCOunt
txtControlArray(ControlArrayCOunt - 1).Top = 300 + (ControlArrayCOunt * 400)
txtControlArray(ControlArrayCOunt - 1).Left = 300
txtControlArray(ControlArrayCOunt - 1).Visible = True
Exit Sub

a:
End Sub
'Command Button to create Control Once Dynamically
Private Sub Command1_Click()
Call Create_Control
End Sub
'Command Button to create Control array Dynamically
Private Sub Command2_Click()
ControlArrayCOunt = ControlArrayCOunt + 1
Call Create_ControlArray
End Sub

maheshsayani
Light Poster
45 posts since Jul 2006
Reputation Points: 10
Solved Threads: 2
 

plz mark solved the problem.

abu taher
Practically a Posting Shark
845 posts since Jul 2008
Reputation Points: 14
Solved Threads: 78
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You