Results 1 to 10 of 23

Thread: Class related Stuff New Instancing

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #21
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    This is a copy of a post somewhere else, just copied here for convenience, as it has some conclusion on class stuff


    This is post https://www.excelfox.com/forum/showt...ll=1#post24217
    https://www.excelfox.com/forum/showthread.php/2966-Class-related-Stuff-New-Instancing?p=24217&viewfull=1#post24217
    https://www.excelfox.com/forum/showt...age2#post24217
    https://www.excelfox.com/forum/showthread.php/2966-Class-related-Stuff-New-Instancing/page2#post24217
    This is frompost https://www.excelfox.com/forum/showt...age2#post24185
    https://www.excelfox.com/forum/showthread.php/2965-Class-related-Stuff-Userforms/page2#post24185
    https://www.excelfox.com/forum/showt...ll=1#post24185
    https://www.excelfox.com/forum/showthread.php/2965-Class-related-Stuff-Userforms?p=24185&viewfull=1#post24185





    An attempt at an initial summary on UserForm (module)
    We are really talking about Class things and class ideas. Inevitably to get some understanding you must accept/ appreciate / be aware of, the hierarchical Object Orientated Programming, (OOP), concept that VBA is modelled on: Very simplified: we start, as it were towards the top, or top left, with classes and from those objects are made and they finally have Properties. The final objects with their properties ( and methods etc.), could be crudely be regarded as some "actual" or significant "things", whereas the class is just the details of how to make the objects, or a template to be used over and over again and added to or filled in appropriately to suit the particular instance like a classic simple example,
    _ The concept of a car could be regarded as a Class,
    _ a particular model as an instance of it,
    _ and a color would be a property.
    ( _ A method could be a way to paint the car, although the OOP is deliberately a bit vague and Methods and Properties often are similar and people argue sometimes as to whether something is a Method or a Property. )
    That is very simplified. It will do for now, but just note we could have something like this in the actual hierarchical structure
    Class - - Class - - Object - - Object - - Object - - Properties
    , or even more complicated. It is not a precise concept. It is what is finally given to us at the user interface

    The VB Editor
    It is almost impossible not to use objects from a class if you are using Excel. By default we have limited direct access to any classes other than to make objects from them, assign variables to them, or modify the properties of the objects made from them.
    The VB editor is a tool we use , often referred to as the development environment, that , amongst other things, by default ,allows us to conveniently look at and develop/ change our objects.
    But there are two sorts of Class that we can create, so as to have our own custom Class. We can use the VB Editor to do that as well

    Use Keys Alt+F11 from Excel to get the VB Editor
    , or alternatively
    , right click on any worksheet tab and select view code, - https://i.postimg.cc/J04LpnsW/Right-...eet-coding.jpg
    Attachment 5865
    ,That will show you initially a representation of some of the existing Excel objects associated with your file, which usually by default will be for the workbook itself, ThisWorkbook, and the worksheets you have. (If you took this second approach to get the VB Editor then initially the big window will be for any coding you may add for the worksheet who’s tab you selected.)
    https://i.postimg.cc/nh69N8KW/Big-wi...u-selected.jpg
    Attachment 5866
    We are for now not interested in the existing things. They are associated with existing Excel objects.
    It is important to realise that most object things in Excel follow the object orientated programming ideas, which for us in the current discussions means they were made from referring to some sort of blueprint / template / set of written instructions etc. We refer to these blueprint / template / set of written instructions etc. as a Class.
    For most of the existing Excel objects, we have only limited, if any, direct access to the Class. That is because it will be propriety information allowing you to construct Excel, so trade secrets as it were.


    We are interested in the available adding of a New Class UserForm. Associated with that UserForm Class thing is one of two class related module types that Microsoft makes available to us.
    "Get one" with a bit of right clicking near the representation of your Excel file in the left hand VBA project window of the VB Editor,
    https://i.postimg.cc/GmZzK54L/Do-a-b...-Form-opti.jpg , https://i.postimg.cc/kgVfxmXY/Do-a-b...orm-option.jpg
    Attachment 5867 , Attachment 5868

    You should then see the basic tools of
    _ a simple pin board looking box or "form", usually with the default name of UserForm1 ,( both for the main class thing and the caption name on the pin board thing top left , ( more to that later ** ) )
    , and
    _ a Toolbox dialog should also be visible. (If it’s not visible select View->Toolbox from the VB editor top ribbon menu. We use the toolbox to add controls to our UserForm.)
    The bottom left window should also now show the properties related to this UserForm
    https://i.postimg.cc/W3Fgbm8z/User-F...-VB-Editor.jpg , https://i.postimg.cc/852WFFXH/User-F...-VB-Editor.jpg


    Note that we have actually added a class, called UserForm1, and the class module that appears is part of the tools we have available for working on it.

    I will change the Name property to suit the previous discussions of this Thread, to ufResults , ** , and note that the Caption did not change,
    https://i.postimg.cc/FzN5szZd/Captio...User-Form1.jpg

    , and we will leave it like that for now, as this will help along the way, to demonstrate a quirk with UserForm Class things, which was brought out by our discussions … Unlike normal classes, UserForms are auto-instantiating, so you can simply call them by name and a new instance of the class is created. ….. as you use ufResults for the first time, a new instance of the form is created.
    It's confusing because you effectively get a variable of the same name as the class. ###

    This last statement we will come back to after getting the basics behind us now.
    Just note finally this ufResults is actually the name of the Class, and just as with, for example,

    Important summary of what we have so far.
    So we have a class now. Parts of this class is the added UserForm module. The name ufResults is effectively the name of the greater thing that is the Class. Exactly what that greater thing is, is deep in the innards of Excel and Office, it concerns how the thing eventually works , and is anyone’s guess in the meantime what / where it is. We are only interested in the available interface that we see, which we can use to determine what sort of object can be made from it. We are only concerned with tools and interface given to us to help shape how the blueprint / template / set of written instructions etc finally "looks". But note what we see and finally have is not much more significant than an instruction manual. Itself it will not "do anything". We use it to make the ( or as many as we like ) final object(s) that "does" something.
    Generally a class is designed to be used over and over again, just like a template.

    What is a class- what we have so far
    As we said previously , it’s a blueprint / template / set of written instructions
    In simple layman beginner terms its like a piece of paper in your pocket with some notes and instructions on how to build an object of this type / class. Apart from the information on it, as a thing its pretty insignificant in itself.
    The whole point of the class module(s) available to us, is just to
    _ make it more convenient to have the text / instructions / explaining diagrams etc. conveniently for you to get at in Excel and use automatically / programmatically, and thereby automatically build an object from
    , rather than
    _ having to painstakingly read from the bit of paper and manually construct the thing and manually add coding to it etc.
    A main difference between A UserForm class module, and the other standard "normal" Class module, is that we have that main extra box with grid points on it, and other bits and pieces in the tool box, like empty lists and boxes, to make it a bit easier to fill in. In simplest layman terns, the difference between,
    _ For a normal class module being like a blank piece of paper . Mainly you would put the text of coding you were interested in for you final object, on it. (Part of that typical coding text is there for you to select and add to, to save you a bit of time typing)
    , and
    _ The UserForm is similar, but like a bit of Graph paper along with some other pre prepared bits and pieces to stick on it. Associate with most of those things are then also available part of the text of coding that might be typically associated with those things, there for you to select and add to, to save you a bit of time typing


    Coding associated with a UserForm Class
    There isn’t any. (That is why we cannot, by default, debug / step mode any text in coding form that we add to it). A class module is just a piece of paper with text, and in the case of a UserForm Class , text and a few other graphical things on it.
    Obviously, although technically correct, any quick look at Class module being in every day use, or being developed by somebody, and it’s associated bits and pieces in the VB Editor will suggest that something looking like coding is around. So what is that about. We will get on to that in the over next post
    Last edited by DocAElstein; 06-15-2024 at 08:50 PM.

Similar Threads

  1. Class related Stuff Userforms
    By DocAElstein in forum Test Area
    Replies: 29
    Last Post: 06-08-2024, 01:22 PM
  2. Class Stuff: VBA Custom Classes & Objects, Class Modules
    By DocAElstein in forum Excel and VBA Tips and Tricks
    Replies: 29
    Last Post: 06-02-2024, 01:49 PM
  3. Replies: 42
    Last Post: 05-29-2023, 01:19 PM
  4. Gif Image Video stuff testies
    By DocAElstein in forum Test Area
    Replies: 13
    Last Post: 09-06-2021, 01:07 PM
  5. Test my rights , to do stuff
    By TestAccount in forum Test Area
    Replies: 0
    Last Post: 10-07-2020, 11:49 AM

Posting Permissions

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