Results 1 to 25 of 25

Thread: [RESOLVED] Question regarding Controls

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    20

    Resolved [RESOLVED] Question regarding Controls

    Presently, I have a number of checkbox controls appropriately named:

    CheckBox1
    CheckBox2
    CheckBox3
    CheckBox4
    etc.

    Is there a way to use and array and loop to assign the name of the control instead of continually put a bunch of if's and else's. For example, this is what I have now:

    VB Code:
    1. If ActiveCell.Value = "NC" Then
    2.      CheckBox1.Value = False
    3. Else
    4.      CheckBox1.Value = True
    5. End If
    6.  
    7. If ActiveCell.Value = "NC" Then
    8.      CheckBox2.Value = False
    9. Else
    10.      CheckBox2.Value = True
    11. End If

    I can put the rest of the If's and Else's...but that's just bad programming. Any suggestions would be greatly appreciated!
    Last edited by Hack; Jan 26th, 2006 at 07:30 AM.

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Question regarding Controls

    Hi Sacto95827 ! Welcome to the forums.

    Consider using a control array instead of multiple separate checkboxes.
    If you use control array, you can use the Index property to set values very easily.

    These two tutorials may help you:
    1. VBExplorer Array Tutorial

    2. Control Arrays In VB6

    After reading them read this very interesting tutorial : Creating Controls At Runtime.

    Also you may want to use Select-Case instead of nested Ifs.
    Last edited by iPrank; Jan 24th, 2006 at 05:33 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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

    Re: Question regarding Controls

    Welcome to the Forums.

    Loop through the OLEObjects colection for the checkboxes on your Excel Sheet.

    VB Code:
    1. Dim i As Integer
    2. For i = 1 To Sheet1.OLEObjects.Count
    3.     If Left$(Sheet1.OLEObjects(i).Name, 8) = "CheckBox" Then
    4.         If Sheet1.OLEObjects(i).Object.Value = False Then
    5.             Debug.Print Sheet1.OLEObjects(i).Name
    6.         End If
    7.     End If
    8. Next
    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

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Question regarding Controls

    Is it an Excel question ?

    Sorry.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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

    Re: Question regarding Controls

    I think so as hes using the "CheckBox" control which is an Office control name vs. "Check" which is VB 6 control name. Plus, hes refering to the "ActiveCell" as in an Excel spreadsheets ActiveCell property. I could be wrong though.
    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

  6. #6
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Quote Originally Posted by Sacto95827
    Presently, I have a number of checkbox controls appropriately named:
    Is there a way to use and array and loop to assign the name of the control instead of continually put a bunch of if's and else's. For example, this is what I have now:

    Any suggestions would be greatly appreciated!
    Rename the first toCheckBox Make it's Index Property to '0'..
    Now rename each of your checkboxes to CheckBox , The index will automaticaly increment on each change..

    Now you have an array of Checkbox..

    check and change with
    VB Code:
    1. Dim Loop_1 as long
    2. For Loop_1 = 0 To Ubound(CheckBox)
    3. If ActiveCell.Value = "NC" Then
    4.      CheckBox(Loop_1).Value = False
    5. Else
    6.      CheckBox(Loop_1).Value = True
    7. End If
    8. Next Loop_1

    Hope this helps..

    Gremmy.....
    Last edited by SAGremlin; Jan 24th, 2006 at 05:49 PM.
    ____________________________________________

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

    Re: Question regarding Controls

    Hey Gremmy, wont that cause a Loop without Do error having Loop as a variable name?
    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

  8. #8
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Quote Originally Posted by RobDog888
    I think so as hes using the "CheckBox" control which is an Office control name vs. "Check" which is VB 6 control name. Plus, hes refering to the "ActiveCell" as in an Excel spreadsheets ActiveCell property. I could be wrong though.
    No Its CheckBoxn In VB 6 too...

    Gremmy..
    ____________________________________________

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

    Re: Question regarding Controls

    Did you verify that? "Check1" for me when adding a new check box to my form.
    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

  10. #10
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Ahh thanks... Fixed it in original post....
    ____________________________________________

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

    Re: Question regarding Controls

    No prob.

    Hey, I thought I recognized you. Your GremlinSA the Invader!

    Sup!
    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

  12. #12
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Quote Originally Posted by RobDog888
    Did you verify that? "Check1" for me when adding a new check box to my form.
    Yes.. In VB 5 and VB 6.. (Both Pro Editions...)

    100% sure...

    Gremmy...
    ____________________________________________

  13. #13
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Quote Originally Posted by RobDog888
    No prob.

    Hey, I thought I recognized you. Your GremlinSA the Invader!

    Sup!
    Now what gave you that idea ????? The Avatar, The signature, or the Nick ...

    It took 4 Days before someone recognised me....

    Gremmy...
    ____________________________________________

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    20

    Re: Question regarding Controls

    RobDog888 is right, I am using Excel. Come to think of it...I slightly recall using control arrays now when I went to school...ouch...that was a long time ago. But I don't think Excel gives you the ability to implement a control array...

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

    Re: Question regarding Controls

    No, I thought you had registered as the same user name as at CG. GremlinSA. Guess your were a bit dyslexic when you registered.
    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

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

    Re: Question regarding Controls

    Quote Originally Posted by Sacto95827
    RobDog888 is right, I am using Excel. Come to think of it...I slightly recall using control arrays now when I went to school...ouch...that was a long time ago. But I don't think Excel gives you the ability to implement a control array...
    No, you cant do it the VB6 way of Copy the control and paste it to invoke an array but as Gremmy posted you can use its .Index property for the same effect.


    w00t w00t! I was right.
    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

  17. #17
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Quote Originally Posted by RobDog888
    No, I thought you had registered as the same user name as at CG. GremlinSA. Guess your were a bit dyslexic when you registered.
    No.. Just under cover... (Let's move this To Chit Chat...)

    Gremmy...
    ____________________________________________

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    20

    Re: Question regarding Controls

    Quote Originally Posted by RobDog888
    No, you cant do it the VB6 way of Copy the control and paste it to invoke an array but as Gremmy posted you can use its .Index property for the same effect.


    w00t w00t! I was right.
    I checked all properties...no Index properties...and when I manually attempt to assign the Index property in VB...it doesn't allow me to do it...am I missing something?

  19. #19
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Quote Originally Posted by Sacto95827
    I checked all properties...no Index properties...and when I manually attempt to assign the Index property in VB...it doesn't allow me to do it...am I missing something?
    Lets try to clear this up..

    Please post what software your using.. (VB, Execel VBA.. Windows) and if posible the Versions...

    Gremmy..

    ------ Edit -----

    Ok ignore this post...

    I just saw your using Excel VBA .. Still what ver??

    ------ End Edit ------
    Last edited by SAGremlin; Jan 24th, 2006 at 07:23 PM. Reason: I cant read.....
    ____________________________________________

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    20

    Re: Question regarding Controls

    Quote Originally Posted by SAGremlin
    Lets try to clear this up..

    Please post what software your using.. (VB, Execel VBA.. Windows) and if posible the Versions...

    Gremmy..

    ------ Edit -----

    Ok ignore this post...

    I just saw your using Excel VBA .. Still what ver??

    ------ End Edit ------
    Excel 2003 (11.6355.6568) SP1
    VB 6.3 Version 9972

  21. #21
    Member SAGremlin's Avatar
    Join Date
    Jan 2006
    Location
    JHB South Africa...
    Posts
    58

    Re: Question regarding Controls

    Quote Originally Posted by Sacto95827
    Excel 2003 (11.6355.6568) SP1
    VB 6.3 Version 9972
    I just double checked this in Excel 2000.. Definitely no index.. Some others are not there either.. ( I didn't know that VBA was that far stripped down) so you will have to use RobDogs OleObjects method..

    Gremmy.
    ____________________________________________

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

    Re: Question regarding Controls

    Ok, are these checkboxes from the Forms toolbar or from the Control Toolbox toolbar?
    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

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    20

    Re: Question regarding Controls

    Quote Originally Posted by RobDog888
    Ok, are these checkboxes from the Forms toolbar or from the Control Toolbox toolbar?
    Control Toolbox Toolbar...

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

    Re: Question regarding Controls

    Then code from post #3 or #6 should work behind the sheet with the checkboxes on it.
    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

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    20

    Re: Question regarding Controls

    Thanks all!

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