|
-
Jan 24th, 2006, 05:14 PM
#1
Thread Starter
Junior Member
[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:
If ActiveCell.Value = "NC" Then
CheckBox1.Value = False
Else
CheckBox1.Value = True
End If
If ActiveCell.Value = "NC" Then
CheckBox2.Value = False
Else
CheckBox2.Value = True
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.
-
Jan 24th, 2006, 05:28 PM
#2
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.
-
Jan 24th, 2006, 05:33 PM
#3
Re: Question regarding Controls
Welcome to the Forums.
Loop through the OLEObjects colection for the checkboxes on your Excel Sheet.
VB Code:
Dim i As Integer
For i = 1 To Sheet1.OLEObjects.Count
If Left$(Sheet1.OLEObjects(i).Name, 8) = "CheckBox" Then
If Sheet1.OLEObjects(i).Object.Value = False Then
Debug.Print Sheet1.OLEObjects(i).Name
End If
End If
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2006, 05:34 PM
#4
Re: Question regarding Controls
Is it an Excel question ? 
Sorry.
-
Jan 24th, 2006, 05:37 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2006, 05:37 PM
#6
Member
Re: Question regarding Controls
 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:
Dim Loop_1 as long
For Loop_1 = 0 To Ubound(CheckBox)
If ActiveCell.Value = "NC" Then
CheckBox(Loop_1).Value = False
Else
CheckBox(Loop_1).Value = True
End If
Next Loop_1
Hope this helps..
Gremmy.....
Last edited by SAGremlin; Jan 24th, 2006 at 05:49 PM.
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 05:39 PM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2006, 05:43 PM
#8
Member
Re: Question regarding Controls
 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..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 05:44 PM
#9
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2006, 05:49 PM
#10
Member
Re: Question regarding Controls
Ahh thanks... Fixed it in original post....
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 05:54 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2006, 05:55 PM
#12
Member
Re: Question regarding Controls
 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...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 06:00 PM
#13
Member
Re: Question regarding Controls
Now what gave you that idea ????? The Avatar, The signature, or the Nick ...
It took 4 Days before someone recognised me.... 
Gremmy...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 06:01 PM
#14
Thread Starter
Junior Member
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...
-
Jan 24th, 2006, 06:02 PM
#15
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2006, 06:03 PM
#16
Re: Question regarding Controls
 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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2006, 06:14 PM
#17
Member
Re: Question regarding Controls
 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...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 06:51 PM
#18
Thread Starter
Junior Member
Re: Question regarding Controls
 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?
-
Jan 24th, 2006, 07:16 PM
#19
Member
Re: Question regarding Controls
 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.....
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 07:30 PM
#20
Thread Starter
Junior Member
Re: Question regarding Controls
 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
-
Jan 24th, 2006, 07:48 PM
#21
Member
Re: Question regarding Controls
 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.
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving & sizing Images , Animation 1 , 2 , 3 , User Controls
Projects & Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom, moving images : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Other Projects : Direct Physics - Inter Wise Proxy
Find me in VB6., VB.NET , Writing Articles, My Genealogy, wiccca Forum ____________________________________________
-
Jan 24th, 2006, 07:50 PM
#22
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 25th, 2006, 11:34 AM
#23
Thread Starter
Junior Member
Re: Question regarding Controls
 Originally Posted by RobDog888
Ok, are these checkboxes from the Forms toolbar or from the Control Toolbox toolbar?
Control Toolbox Toolbar...
-
Jan 25th, 2006, 11:37 AM
#24
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 25th, 2006, 04:18 PM
#25
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|