Consulting

Results 1 to 8 of 8

Thread: Solved: What's the use of a class module

  1. #1
    VBAX Regular
    Joined
    Sep 2011
    Posts
    78
    Location

    Solved: What's the use of a class module

    I am unable to work out the use of class modules as they seemed to be private by default and I am unable to call any procedures in a class module from a form or another module.

    So what's the use of a class module?


  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You simply declare any routines that should be public as Public.
    Be as you wish to seem

  3. #3
    VBAX Regular
    Joined
    Sep 2011
    Posts
    78
    Location
    Thanks for your reply.

    The procedures are declared public. No Luck!

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    For an example how to use a class module have a look over here:

    http://www.snb-vba.eu/VBA_Userform_i...ntrole_en.html

  5. #5
    VBAX Regular
    Joined
    Sep 2011
    Posts
    78
    Location
    Thanks, snb. It will take some time to digest, but like the link you provided about my post regarding renaming modules, this information open new doors.

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    My guess would be that you weren't creating an instance of the class when trying to call its methods?
    Be as you wish to seem

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    A Class Module is a blueprint of a custom Object. Once you have defined the custom object, you have to create, (Instantiate,) the object with the New keyword, just like creating a new Collection. Then you can use any custom methods, Properties, and Events just like with any other Object.

    [vba]Dim X As New Collection
    With X
    .Add(Item, Key)
    ,Add(Item,Key)
    End With
    Z = X.Count[/vba] [vba]Dim Y As New c_MyClass
    With Y
    .CustomMethod(Parameters) 'Private Sub
    End With
    Z = Y.CustomProperty 'Property Get Sub[/vba]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    VBAX Regular
    Joined
    Sep 2011
    Posts
    78
    Location
    I used custom classes in dBase, quite different from this. I appreciate all the replies and assistance. It opens new doors that I will certainly explore and would put to good use.

Posting Permissions

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