By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,630 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,630 IT Pros & Developers. It's quick & easy.

Array of buttons, each one using a common procedure

P: 3
I have an array of 16 control buttons. Their click routines set a unique identifier code. All buttons then vector to a common procedure. How do I relate the identifier to the Button object i.e. If I press button 15, I need to operate on btnChannel15, if button 3, on btnChannel3, etc. (how do I incorporate a variable component into each Button Object's name)? I'm relatively new to VB, and a newbie to this forum, so I'd appreciate any pointers in the right direction.
Mar 24 '07 #1
Share this Question
Share on Google+
4 Replies


vijaydiwakar
100+
P: 579
I have an array of 16 control buttons. Their click routines set a unique identifier code. All buttons then vector to a common procedure. How do I relate the identifier to the Button object i.e. If I press button 15, I need to operate on btnChannel15, if button 3, on btnChannel3, etc. (how do I incorporate a variable component into each Button Object's name)? I'm relatively new to VB, and a newbie to this forum, so I'd appreciate any pointers in the right direction.
use index property like
if index=1 then ' code
this index is inbuilt in function whenevr u create ctrl array
Mar 24 '07 #2

SammyB
Expert 100+
P: 807
I have an array of 16 control buttons. Their click routines set a unique identifier code. All buttons then vector to a common procedure. How do I relate the identifier to the Button object i.e. If I press button 15, I need to operate on btnChannel15, if button 3, on btnChannel3, etc. (how do I incorporate a variable component into each Button Object's name)? I'm relatively new to VB, and a newbie to this forum, so I'd appreciate any pointers in the right direction.
What VB are you using: VBA (as part of an Office application such as Access), VB6, VB.NET 2003, or VB.NET 2005?

BTW, welcome to The Scripts, like you I am a gray beard, except mine is much grayer: started 1962 on an IBM 1410

Mar 24 '07 #3

P: 3
What VB are you using: VBA (as part of an Office application such as Access), VB6, VB.NET 2003, or VB.NET 2005?

BTW, welcome to The Scripts, like you I am a gray beard, except mine is much grayer: started 1962 on an IBM 1410

Thanks for the response. I'm using VB.NET, but I think it's slightly before 2003, although it seems pretty compatible with my copy of Halvorson's "Visual Basic.net Step By Step," which is on the 2003 product.
Mar 26 '07 #4

Expert 5K+
P: 8,434
I have an array of 16 control buttons. Their click routines set a unique identifier code. All buttons then vector to a common procedure. How do I relate the identifier to the Button object i.e. If I press button 15, I need to operate on btnChannel15, if button 3, on btnChannel3, etc. (how do I incorporate a variable component into each Button Object's name)? I'm relatively new to VB, and a newbie to this forum, so I'd appreciate any pointers in the right direction.
Ironically, VB6 had exactly the functionality you need. You could allocate controls in an array, with all the functionality that implies - loop processing, a single event procedure which receives an index to identify which control produced the event, and so on.

For reasons I have been unable to fathom (does anyone know?) M$ decided to remove this incredibly useful feature in VBA (probably understandable) and VB.Net.

There has been quite a bit of posting here on the topic of simulating a control array. The basic technique, as suggested (I think) by M$ is to set control names with a number on the end as you have done, and use various bits of code to translate back and forth.

I recently proposed an alternative method, right here on TheScripts. :D The idea is to define an array of a generic type such as Object or (assuming it’s available in .Net) Control, and start out at form load by setting each of the elements in the array to point to one of your “array” of controls. The technique has not been fully investigated, as I haven’t had the time, but the basic idea should be sound. And it should allow you to access your controls using proper array processing.

Try a search (see the search box, top-right of the page) of TheScripts for terms such as “VB simulate control array” - you should find plenty of info to get you started.

Incidentally, I'm not quite the "greybeard" you claim to be, but have been dabbling with VB since version 1. Haven't made it past VB6, though. I plan to start looking into the .Net version "real soon now". Probably the 2003 version, since I already have that (got it as part of an MSDN subscription).
Mar 26 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.