|
-
Nov 23rd, 2000, 01:55 PM
#1
Thread Starter
Frenzied Member
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]
-
Nov 23rd, 2000, 02:05 PM
#2
Addicted Member
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]
-
Nov 23rd, 2000, 05:20 PM
#3
Thread Starter
Frenzied Member
Cheers, m8 that will help loads in my scripting language.
-
Nov 23rd, 2000, 05:26 PM
#4
Thread Starter
Frenzied Member
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.
-
Nov 23rd, 2000, 06:40 PM
#5
transcendental analytic
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.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|