-
August 13th, 2009, 01:45 PM
#1
[RESOLVED] Create an object durring runtime in code
OK, I know how to create an object as arrays. See this example:
Code:
Load Text1(1)
Text1(1).Visible = True
Text1(1).Top = 0
Text1(1).Left = 0
I want the exact same effect but this time without an abject being part of an array. Example: Intead of load Text1(1), I would load Text2. Is this possible, if so, HOW?
Thank's
David Richard
-
August 13th, 2009, 02:53 PM
#2
Re: Create an object durring runtime in code
Code:
Dim t1 As TextBox
Set t1 = Controls.Add("VB.TextBox", "Text2")
or simply
Code:
Controls.Add "VB.TextBox", "Text2"
-
August 13th, 2009, 03:29 PM
#3
Re: Create an object durring runtime in code
Thank you! It works.
One thing though:
Code:
Controls.Add "VB.Textbox", "Text2"
Will not work by itself. If you need to use Text2's reference, It does not work. The first example is the one to follow! So when you want to set Visible to true or it's size and position, The Set Var = methode is the best.
Thank you again WoF!
David Richard
-
August 13th, 2009, 04:51 PM
#4
Re: [RESOLVED] Create an object durring runtime in code
You are welcome.
I didn't know. I would have expected, after Controls.Add "VB.TextBox", "Text2", you could use Text2.Visisble or whatever throughout your code, but come to think of it, that is not possible. Text2 ist not known to the compiler at compile time, so it cannot build references to it. The object comes in by late binding during runtime. So you must care to keep a reference to it, like t1, to keep references to it working, because its name is but a string and not evaluated at compile time.
Good job to clear that.
Tags for this Thread
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
|