Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: Class related Stuff Userforms

  1. #21
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    https://www.excelfox.com/forum/showt...serforms/page3
    https://www.excelfox.com/forum/showt...age3#post24224
    https://www.excelfox.com/forum/showt...ll=1#post24224




    A few random UserForm Examples,
    using coding behind Form things

    For both the main UserForm grid and anything we may, (from the tool box**) put on it, we have available coding "behind" it. This is mainly in the form of being able to tap into, that is to say, add to coding that is done when certain things take place. Usually this sort of coding is referred to as event coding.
    **Note as ever, we are not talking about anything that could be regarded as things or objects here, - even if we appear to insert from, or drag things from, to the main grid from the tool box, because these are really notes / sketches / templates from which the more substantial "thing" / object will be made by the New in the typical initial instanciating steps such as
    Rem 1 making an instance of ufResults
    Dim objufResults As ufResults
    Set objufResults = New ufResults


    We remember also the confusing complicating for the class UserForm that it is self instantiating, meaning that if we missed out that initial coding section, then it would effectively be done for us, automatically, the first time we tried to use our ufResults, pseudo like
    Dim ufResults As ufResults
    Set ufResults = New ufResults

    , meaning effectively we have an object variable which has the same name as the class from which it comes. – Very annoyingly confusing. Note, of course, that I have made the object purple just for ease of explanation. In the VB editor it will be black, and will be exactly the same word as the ufResults of the Class, as also appearing, for example, on the Class module
    https://i.postimg.cc/8PtpzHW6/uf-Results.jpg
    ufResults.JPG
    Attached Files Attached Files
    Last edited by DocAElstein; 06-10-2024 at 11:41 AM.

  2. #22
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    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.

  3. #23
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    gjhg

  4. #24
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    gjhg
    Last edited by DocAElstein; 06-01-2024 at 11:03 PM.

  5. #25
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    later
    Last edited by DocAElstein; 06-09-2024 at 11:00 AM.

  6. #26
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    later
    ….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!!

  7. #27
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    later
    ….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!!

  8. #28
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    later
    ….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!!

  9. #29
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    er later

  10. #30
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,446
    Rep Power
    10
    er later

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
  •