Results 1 to 8 of 8

Thread: Add extra methods to objects?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Netherlands
    Posts
    4

    Question Add extra methods to objects?

    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

  2. #2
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Yes, you can take the regular text box and create a better ActiveX control adding any methods/properties you wish.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Netherlands
    Posts
    4
    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

  4. #4
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    www.vbworld.com

    You'll find tuturials on creating activex controls.
    It's a type of project in VB.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'class code we'll name it cTxtExtender
    2. Private WithEvents useBox as TextBox
    3.  
    4. Public Property Get Box() as TextBox
    5.    Set Box=useBox
    6. End Proeprty
    7.  
    8. Public Sub Setup(txtbox as TextBox)'if you make this class outside of the exe then you'll have to switch it to object
    9.    Set useBox=txtbox
    10.    'now you can use that control and even receive events from it
    11. End Sub
    12.  
    13. 'add functions
    14. Public Sub Email()
    15.    'some error handling
    16.    If useBox is nothing then
    17.       Err.Raise vbObjectError + 512, "TextBox Extender", "Textbox not set yet."
    18.       Exit Sub
    19.    End If
    20.  
    21.    'add your email code here
    22. End Sub
    23.  
    24. Private Sub Class_Terminate()
    25.    Set useBox=Nothing
    26. End Sub
    27.  
    28.  
    29. 'this is the form code or how to use it
    30. Private TxtEx as New cTxtExtender
    31.  
    32. Private Sub Form_Load()
    33.    TxtExt.Setup Text1
    34.    'to use a function
    35.    TxtExt.Email
    36.    'to access normal textbox stuff either use the textbox directly or
    37.    TxtExt.Box.Text="Hey there"
    38. End Sub
    39.  
    40. Private Sub Form_Unload(Cancel As Integer)
    41.    Set TxtEx=Nothing
    42. End Sub

  6. #6
    Addicted Member
    Join Date
    May 1999
    Posts
    161
    Very nice post from Edneeis...

    I love clean and simple solutions like that...

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Netherlands
    Posts
    4
    And how about adding extra properties?
    Is this possible too?

    ColdSTone

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width