Results 1 to 6 of 6

Thread: Class Module Question

  1. #1

    Thread Starter
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344

    Class Module Question

    What i want to do is when i click on cmdBla that will call a function in my class module which will HIGGHLIGHT the text located in the textbox. This is what i am have, and what i am trying.

    cmdBla
    ----------

    HighlightTextBox(txtWineTypeName)


    CLASS MODULE
    ------------------------
    Private Function HighlightTextBox(oSelect As Object)
    oSelect.SetFocus
    oSelect.SelStart = 0
    oSelect.SelLength = Len(oSelect.Text)
    End Function

    -----------------------------------------------------------------------------

    Now that is not doing what its suppose to . Any way all help would be apreciated THX.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Have you instanciated an object of your class?
    VB Code:
    1. Private obj As YourClassName
    2.  
    3. Private Sub Form_Load()
    4.     Set obj = New YourClassName
    5. End Sub
    6.  
    7. Private Sub cmdBla()
    8.     obj.HighlightTextBox txtWineTypeName 'you cant use parantheses here if this isnt a function
    9. End Sub
    Best regards

  3. #3

    Thread Starter
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344

    Just tried it that way :)

    It didn't work for me that way i tried to work around it as well but nothing, . Thx for the help anyway.

    Where it gives me the error ir right away in form load, the error says

    Set oSelect = New CWineModule

    it highlights Oslect and says

    Variable Not Defined
    Last edited by Tequila_worm; Jan 20th, 2002 at 05:35 AM.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    When you're passing an object or a control to a sub you can't use parantheses because you will then pass it ByVal instead of ByRef.
    (As mentioned in the comments of my earlier post).

    Best regards

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Did you declare a variable oSelect in your form first before you set it? Should be kinda like this:
    VB Code:
    1. 'In the form
    2. dim myObj as CWineModule
    3. Set myObj=New CWineModule
    4.  
    5. myObj.HighlightTextBox txtWineTypeName
    6.  
    7.  
    8. 'then in the class module CWineModule
    9. Public Sub HighlightTextBox(oSelect As Textbox)
    10.   oSelect.SetFocus
    11.   oSelect.SelStart = 0
    12.   oSelect.SelLength = Len(oSelect.Text)
    13. End Sub

    Make sure any subs or functions you want to call from the class are public and as long as its a class in the project not a dll you can pass the object as a textbox instead of the generic object., also since you don't return anything you'd make it a sub instead of a function.

  6. #6

    Thread Starter
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344

    Thanks for the help

    That was it man, they had to be a Public function, holly crap man thx for you help.
    Last edited by Tequila_worm; Jan 20th, 2002 at 02:31 PM.

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