Results 1 to 10 of 30

Thread: Class related Stuff Userforms

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,451
    Rep Power
    10
    https://www.excelfox.com/forum/showt...ll=1#post24187
    https://www.excelfox.com/forum/showt...age3#post24187



    Initiataelize Starting
    Before dragging any template sketches from the tool box, we can take a look at what is available for coding associated primarily with the main grid, that is to say the coding "behind" the main form.
    One of the first ones that is perhaps worth an initial consideration is the Initialize Event of the VBA UserForm. To get the possibility to add to the coding for that ,
    _ Right-click on the main UserForm grid showing in the VB Editor, and select View Code from the menu.
    _ In the Dropdown list on the left above the main Window, select UserForm.
    _ This will typically give something for you to add to the UserForm_Click() event. You can ignore this.
    _ In the Dropdown list on the right above the main Window, select Initialize.
    (_ Optional: Delete the UserForm_Click() sub which appeared in step 2. The event coding for this and all the other available will be there anyway on an instantiated object , at this stage it is just a bit of worthless text ignored when the Class is used to make an actual object )
    Remember as ever, this is all just text, which will never itself be anything of significance. It is just used later by a user New, ( or the effective automatically done one )
    https://i.postimg.cc/264GZpGV/Initia...-User-Form.jpg https://i.postimg.cc/05YX6SXc/Initia...-User-Form.jpg
    Initialize Event of the VBA UserForm.jpgInitialize Event VBA UserForm.JPG
    Code:
    Private Sub UserForm_Initialize()
    
    End Sub
    As with all the event coding that is already available to us in VBA, this coding ios there with things in it that Microsoft prefer us not to see. This is understandable as it would be proprietary information and part of what is effectively the software Office Excel. But we can add our coding to it, for example a simple message box.

    We will do this in a way to help us once again get clear the point about the possibility to neglect an instanciating,
    Currently we have in the example file uploaded in the last post, two UserForm Classes, ufResults and UserForm1
    We will put the same coding in both. This will be a message box to tell us the class name
    Code:
    Option Explicit
    Private Sub UserForm_Click()
    
    End Sub
    
    
    Private Sub UserForm_Initialize()
     MsgBox Prompt:="You just Initiataelized an object from the class  " & Me.Name
    End Sub
    
    https://i.postimg.cc/qBK7WV5R/uf-Results-Initialize.jpg https://i.postimg.cc/8PVCSK2b/User-Form1-Initialize.jpg
    UserForm1_Initialize().JPGufResults_Initialize().JPG
    That coding will tell me the class name of the particular UserForm being "made"
    Now we will do the coding to Instanciate, that is to say, "make" as it were, an object of each class. Remember this is generally what happens by the [color=Blue]New[/color] bit of the typical early declaration coding at the start of a coding to use the UserForm who’s class we made. We want to do this in two different ways, so as to demonstrate once again the confusing phenomena of a UserForm self instantiating if you neglect to do it.
    These next codings can go inside any of the existing default modules.
    Code:
    Option Explicit     '      https://www.excelfox.com/forum/showthread.php/2965-Class-related-Stuff-Userforms?p=24187&viewfull=1#post24187
    Sub Instanciate_ufResults()
    Dim Fm As ufResults
     Set Fm = New ufResults ' Fm  becomes the object variable pointing to an actual  "thing"  or  object which the  New  efferctively caused to be "made"
    End Sub
    Sub Instanciate_UserForm1()
      MsgBox prompt:=UserForm1.Visible  '  This code bit    =UserForm1.Visible   effectively does the followoing
    '                UserForm1.         '  This effectively causes the next two lines to be done  internally as it were
    '                         Dim UserForm1 As UserForm1
    '                          Set UserForm1 = New UserForm1 '  UserForm1  becomes the object variable pointing to an actual  "thing"  or  object which the   New   effectively caused to be "made"  from using the class UserForm1
    ' MsgBox prompt:=UserForm1.Visible              '  (This should return  False   because  the form , is not visible) 
    End Sub
    
    Last edited by DocAElstein; 06-10-2024 at 05:27 PM.

Similar Threads

  1. 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
  2. Replies: 42
    Last Post: 05-29-2023, 01:19 PM
  3. Test my rights , to do stuff
    By TestAccount in forum Test Area
    Replies: 0
    Last Post: 10-07-2020, 11:49 AM
  4. 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
  5. Pass Values Between Multiple Userforms
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 07-24-2011, 03:25 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
  •