julianpointer
asked on
Referencing Class Objects
I have a class which declares controls as
Public WithEvents txtName As TextBox
I need to be able to check that the class actually does have this control object. I will use many of these classes.
Ideally I want to be able to do is reference the classes controls like class("txtName") or something similar.
Public WithEvents txtName As TextBox
I need to be able to check that the class actually does have this control object. I will use many of these classes.
Ideally I want to be able to do is reference the classes controls like class("txtName") or something similar.
if you need it for a TextBox - why not use ACtiveX Control or UserControl ?
you can add EVENTS for that too.
you can add EVENTS for that too.
You can do it with a user control no problem.. but if you write and compile a seperate ActiveX control, than that's just one more thing to distribute with your application...
ohmygod
ASKER
Hi datacop, thanks for your help but what im after is a way to assign dynamically controls that are created at run time to a class with the controls events.
All the controls are created dynamically on an instance of a child form. I then set the child form's controls it's class control(only if it exists in the class).
What I need to do is check that in the class there is an object called txtName that I will then set to the txtName created on the child form.
All the controls are created dynamically on an instance of a child form. I then set the child form's controls it's class control(only if it exists in the class).
What I need to do is check that in the class there is an object called txtName that I will then set to the txtName created on the child form.
Try the CallByName function in VB6.
If the Property you are calling does not exist, you'll get a runtime error which you can trap.
ASKER
No, this is for functions only.... I need to be able to check if an object exists in the class.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks twuyst, works a treat... just what i wanted.
should it work in VB5 ?
-> cExtender is not defined.
-> cExtender is not defined.
Let me explain like this..
In your class module (call it MyClass):
public withevents txtname as TextBox
' from this point on, you can access it
' just like if you were to place a
' control on a form..
private sub txtname_GotFocus()
txtname.selstart = 0
txtname.sellength = len(txtname.text)
end sub
Now, on the form that your going to use this new class. create a new textbox (name it text1)
dim cMyClass as MyClass
private sub form_load()
set cMyClass = new MyClass
set cMyClass.txtName = Text1
At this point, all the event code that you have in your class module will now be "inherited" by the text1 textbox.
I have a standard textbox class that I use that I have written a "style" property into.. based on the value of that property, it will only allow upper case, lower case, or numeric only input.