Is there someone who can tell me if it's possible to add some extra methods to an object?
In other words, is it possible to create textbox1.Email and textbox1.Something?
Thanks in advance, ColdSTone
Printable View
Is there someone who can tell me if it's possible to add some extra methods to an object?
In other words, is it possible to create textbox1.Email and textbox1.Something?
Thanks in advance, ColdSTone
Yes, you can take the regular text box and create a better ActiveX control adding any methods/properties you wish.
Ok, I understand, but how do I create that better ActiveX control?
Is there a special function for that?
Do you know a good tutorial?
ColdSTone
www.vbworld.com
You'll find tuturials on creating activex controls.
It's a type of project in VB.
Or if you just want to add some functions you can also make a 'wrapper' class. Basically you make a class that contains the added functions and a textbox and link it to an existing textbox.
VB Code:
'class code we'll name it cTxtExtender Private WithEvents useBox as TextBox Public Property Get Box() as TextBox Set Box=useBox End Proeprty Public Sub Setup(txtbox as TextBox)'if you make this class outside of the exe then you'll have to switch it to object Set useBox=txtbox 'now you can use that control and even receive events from it End Sub 'add functions Public Sub Email() 'some error handling If useBox is nothing then Err.Raise vbObjectError + 512, "TextBox Extender", "Textbox not set yet." Exit Sub End If 'add your email code here End Sub Private Sub Class_Terminate() Set useBox=Nothing End Sub 'this is the form code or how to use it Private TxtEx as New cTxtExtender Private Sub Form_Load() TxtExt.Setup Text1 'to use a function TxtExt.Email 'to access normal textbox stuff either use the textbox directly or TxtExt.Box.Text="Hey there" End Sub Private Sub Form_Unload(Cancel As Integer) Set TxtEx=Nothing End Sub
Very nice post from Edneeis...
I love clean and simple solutions like that...
And how about adding extra properties?
Is this possible too?
ColdSTone
Sure but usually to access the custom properties you'd use the first level MyObject.CustomProp whereas accessing the actual textbox properties would have another level MyObject.Box.OriginalProp. Just make the properties in the class.