Results 1 to 6 of 6

Thread: Reference to a select of objects

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Reference to a select of objects

    Hi all

    I have a six windows, and on them I have there five objects ListBox but every have different names. e.g LstCity, LstNames, LstHouses, Lst Peoples and LstCars.


    if I would like to execute the same on the all objects (on a one form) then I can this make so - using the loop: For…each O.K. I understand it
    Code:
    Option Explicit
    
    Private Sub ClearListBox()
        Dim ctl As Control
        ' Clear all the ListBoxes on a one form.
        For Each ctl In Controls
            If TypeOf ctl Is ListBox Then ctl.List = ""
        Next ctl
    End Sub
    
    Private Sub cmdClear_Click()
        ClearListBox
    End Sub
    However…..
    I want to execute the same on at will chosen object only and on a one at will chose forms - when this form is actively obviously. How to make it? How to make one code for objects with different name, on a different forms?

    will be usefully some example code

    thank in advance
    I know, I know, my English is bad, sorry .....

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Reference to a select of objects

    Not quite sure what you mean as you have the code and logic so its only a matter of changing the control type, no?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Reference to a select of objects

    I'm thinking (after reading this several times) that the OP wants a single sub to clear all list boxes on a chosen form. So...
    Code:
    Public Sub ClearAllListBoxesInForm(F As Form)
    Dim C As Control
    ' Clear all the ListBoxes on a one form.
    For Each C In F.Controls
      If TypeOf C Is ListBox Then C.List = ""
    Next C
    End Sub
    Good Luck
    Option Explicit should not be an Option!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Reference to a select of objects

    Hmm, that does sound logical.


    Ps, did I just do a Mr Spock impression?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: Reference to a select of objects

    Hi All

    vb5prgrmr wrote:

    I'm thinking (after reading this several times) that the OP wants a single sub to clear all list boxes on a chosen form. So...

    I correct it - then it should be:
    I'm thinking (after reading this several times) that the OP wants a single sub to clear - there NOT all list boxes on a chosen form. So...
    .. So, I want a single sub to clear on at will chosen object ONLY, and on ANY chosen form

    BTW:
    Someone know, how to change the Language in my app? Any way?

    I greet Tamgovb
    Last edited by Tamgovb; May 11th, 2009 at 05:42 PM.
    I know, I know, my English is bad, sorry .....

  6. #6
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Reference to a select of objects

    So you want to clear a specific list box from a general sub... Well then...
    Code:
    Public Sub ClearListBox(LB As ListBox)
    LB.Clear
    End Sub
    Good Luck
    Option Explicit should not be an Option!

Posting Permissions

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



Click Here to Expand Forum to Full Width