-
Hi,
A problem with the textbox class. Add a class to a vb project called CText and enter this code.
Public Sub Add()
Dim newText As TextBox
Set newText = Controls.Add("VB.Textbox", "newText")
With newText
.Visible = True
.Text = "&Dynamically Added Button"
.Top = 0
.Left = 0
.Width = 2400
.Height = 500
End With
End Sub
And then add a form. On the form add this.
Dim nObj As New CText
Public Sub Form_Load()
nObj.Add
End Sub
When irun the project vb gives me an error 424, object required, why does this not work ?
[Edited by PsyVision on 11-23-2000 at 01:58 PM]
-
simply because "Controls" is out of context, it belongs to the form not the class module. Try passing a reference to the form in your class and use that to add controls.
[code]
Public Sub Add(Form As Object)
Dim newText As TextBox
Set newText = Form.Controls.Add("VB.Textbox", "newText")
With newText
.Visible = True
.Text = "&Dynamically Added Button"
.Top = 0
.Left = 0
.Width = 2400
.Height = 500
End With
End Sub
[\code]
-
Cheers, m8 that will help loads in my scripting language.
-
Is there any way to have an array of these. i tried Dim newText(10) as textbox but it says not a legal object name, then setting .index value gives me an error.
-
You can't create control arrays at runtime, although you can create an array of controls, but in that case you can't receive the event of each of them without using a trick with classes and classcollections.