Results 1 to 10 of 30

Thread: Class Stuff: VBA Custom Classes & Objects, Class Modules

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Custom Classes and Custom objects. General and UserForms

    General Class / Class module use
    The Class Module is a Blueprint/Template and the coding in it isn’t coding
    .
    We are now right at where people start:
    Right mouse click in the left hand side project explorer window near the representation of your workbook and select something like --- Insert --- Class Module
    Add a Class module.jpg : https://imgur.com/X2DdZqY : http://i.imgur.com/X2DdZqY.jpg
    Add a Class module.JPG

    If you now double click on the Class1 representation that appears in the VB Editor, a large window appears similar to those code windows already discussed. Although we begin now to discus adding coding into this new window, we are in reality, using similar ideas and concepts to define how the coding in an instantiated object from the Class Blueprint/ template performs. It is convenient to use what looks like coding , because objects made from the template/Blueprint will perform as if such coding is running. The “coding” in the Class Module is actually the instructions / Blueprint / template showing exactly how the coding in the instantiated object modules would look like if we could see them as we can the ThisWorkbook and the Workbooks code modules discussed already.
    A Class module is not really a code module,
    Why by default you can’t step through Class modules in debug ( F8 ) mode
    The fact that what you see is not actual coding, but a Blueprint for coding to use, explains why , by default, stepping through a coding manually in debug ( F8 ) mode, does not step through a Class module. What should happen is that it steps through the coding in an object model at the same level in the OOP hierarchy as the ThisWorkbook and the Workbooks code modules discussed already. The problem is that those actual object code modules do not exists. However the coding in those objects must mirror exactly the Template of the Class module, so VBA gives the option to allow the stepping through a coding manually in debug ( F8 ) mode to go through the class module as if it were the actual coding:
    Tools Options.JPG : https://imgur.com/KZUyPnB http://i.imgur.com/KZUyPnB.jpg
    Break in class modules.JPG : https://imgur.com/75Eg6UE http://i.imgur.com/75Eg6UE.jpg

    Having said this, there could be some logical justification for organising the Class module as it is, since possibly it reflects the coding hidden behind many things which make Excel work…

    Organisation of and using the Class Module
    We are at a point where people first start…
    The form of the text that can go in the Class Module is predefined. We may be able to put some text / code text in of some arbitrary form, but it will not be our choice if they do anything like we want. As noted, the text that is of any practical use will look like coding since it represents the coding inside the object code module which we can not see.

    Event Coding.
    The physical structure of the class code module, that is to say, as it appears on the screen to us, has a similar form to the two object modules already discussed. We only have a couple of Event macros already there
    ClassEventMacros.JPG : https://imgur.com/DvLfX2G http://i.imgur.com/DvLfX2G.jpg
    ClassEventMacros.JPG

    They are fairly explanatory: They do things when we make or break an object…..
    Just to remind us… We can’t do anything with the text , ( or coding as it appears to look ) , in the class module since it is just a set of instructions/ template for how actual code within an object made from it will look. So we need to instantiate, that is to say, bring into existence, an object made from this template: The stuff in the Class module id the template from which an actual object code module will be made. VBA does not let us see those modules
    If we add text code lines within these two procedures, then in an instantiated object, the actual code lines of those forms , will be done at the instantiation, and at the termination of that object. ( The termination would typically be done in a code line in another module of the form Set Obj = Nothing. ( The instantiation/ bringing into life of the object we have already discussed is done by the typical initial Dim / Seting of the object variable, Obj ) )
    This is a very important concept that most people, including a lot of computer experts don’t understand, so I will say it again:
    The text lines looking like code in the Class module are not real code. They represent what the actual code lines in an object code module of an object made from the class will look like. But we will never see those code lines. The makers of Excel decided to prevent us from seeing them. In the case of the two things already discussed ( worksheet object code modules and the ThisWorkbook object code module ) we had the opposite situation: We could see and manipulate the actual object code modules, but we could not see the Class modules used as the template from which to make those. We are guessing that somehow when we start excel, a hidden class module is used as a template to create the ThisWorkbook object code module , and possibly for each of the worksheets that we see, there is a similar class module which we can’t see, which is used as a template to create those.
    Last edited by DocAElstein; 03-03-2021 at 12:34 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. PQ - IP C class generator
    By sandy666 in forum ETL PQ Tips and Tricks
    Replies: 0
    Last Post: 10-22-2020, 05:16 AM
  2. Backup all modules, class modules and userforms to a selectable folder
    By MrBlackd in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 04-06-2014, 08:33 AM
  3. Manipulate VBA Array Object Using Class Module
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 0
    Last Post: 06-06-2013, 07:53 PM
  4. Array Class Module
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 3
    Last Post: 12-20-2012, 11:22 AM
  5. Class Objects Created Using the CreateObject Method That Employs Late Binding
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 08-16-2011, 12:38 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
  •