473,837 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBE 2005 - 'Index' Property For A Control

Guyz,

Whatever happened to the 'Index' property for a control, that used to be
present in
VB 3.0 / 4.0 / 5.0 / 6.0 and which now seems to be missing from VBE 2005?

I need to be able to make 4 command buttons behave in the same way, the
'Index'
property indicating which command button I clicked on.

The 'Index' property is an useful time saver because it saves me making
copies of
the same code to the other command buttons and I needed all command buttons
to behave in exactly the same way.

How do I accomplish this in VBE 2005? Thanks in advance.
SB
Jan 29 '07 #1
5 1330
I'm sorry to tell you this, but control arrays have left the building.
Disappointing, isn't it?

If you want a bunch of buttons to perform the same event, just add your own
event handlers for them in your Form_Load event:

AddHandler myButton1.Click , DoThisForAllOfT hem
AddHandler myButton2.Click , DoThisForAllOfT hem
AddHandler myButton3.Click , DoThisForAllOfT hem
AddHandler myButton4.Click , DoThisForAllOfT hem
AddHandler myButton5.Click , DoThisForAllOfT hem

If you want to know which button invoked the click, you can probably do it
some fancy way (Reflection comes to mind), but I just put some identifier
in the [Tag] property for each button and check that like this:

Private Sub DoThisForAllOfT hem(ByVal sender as Object, ByVal e as
EventArgs)
Dim theButton As Button = DirectCast(send er, Button)
Select Case theButton.Tag
Case "1"
GoToSchool
Case "2"
GoToWork
Case "3"
GoShopping
Case "4"
GoToDinner
Case "5"
GoDrinking
End Select
End Sub

Be sure your buttons have a tag in them, if it is blank, this will throw a
NullException.

Robin S.
-------------------------------------------
"Scanboy" <Sc*****@discus sions.microsoft .comwrote in message
news:70******** *************** ***********@mic rosoft.com...
Guyz,

Whatever happened to the 'Index' property for a control, that used to be
present in
VB 3.0 / 4.0 / 5.0 / 6.0 and which now seems to be missing from VBE 2005?

I need to be able to make 4 command buttons behave in the same way, the
'Index'
property indicating which command button I clicked on.

The 'Index' property is an useful time saver because it saves me making
copies of
the same code to the other command buttons and I needed all command
buttons
to behave in exactly the same way.

How do I accomplish this in VBE 2005? Thanks in advance.
SB

Jan 29 '07 #2
Rob,

Thanks! I have had a look around for control arrays in the VBE help system,
and
found out why. Event handlers made the use of control arrays redundant.

Thanks for introducing me to 'AddHandler', 'RemoveHandler' , 'DirectCast'. I
have
just looked at the 'Control Arrays For Visual Basic 6.0 Users' page.

Would the following code equally work as well?

Private Sub Buttons_Clicked (ByVal Sender As System.Object, _
ByVal SysEvntArgs As System.EventArg s) Handles Button1.Click,
Button2.Click, _
Button3.Click, Button4.Click
Select Case DirectCast(Send er, Button).Name
Case Button1.Name
MsgBox("You clicked on the first button!")
Case Button2.Name
MsgBox("You clicked on the second button!")
Case Button3.Name
MsgBox("You clicked on the third button!")
Case Button4.Name
MsgBox("You clicked on the fourth button!")
End Select
End Sub
SB
-----------------------------------------------------------------------------------------------
"RobinS" wrote:
I'm sorry to tell you this, but control arrays have left the building.
Disappointing, isn't it?

If you want a bunch of buttons to perform the same event, just add your own
event handlers for them in your Form_Load event:

AddHandler myButton1.Click , DoThisForAllOfT hem
AddHandler myButton2.Click , DoThisForAllOfT hem
AddHandler myButton3.Click , DoThisForAllOfT hem
AddHandler myButton4.Click , DoThisForAllOfT hem
AddHandler myButton5.Click , DoThisForAllOfT hem

If you want to know which button invoked the click, you can probably do it
some fancy way (Reflection comes to mind), but I just put some identifier
in the [Tag] property for each button and check that like this:

Private Sub DoThisForAllOfT hem(ByVal sender as Object, ByVal e as
EventArgs)
Dim theButton As Button = DirectCast(send er, Button)
Select Case theButton.Tag
Case "1"
GoToSchool
Case "2"
GoToWork
Case "3"
GoShopping
Case "4"
GoToDinner
Case "5"
GoDrinking
End Select
End Sub

Be sure your buttons have a tag in them, if it is blank, this will throw a
NullException.

Robin S.
-------------------------------------------
"Scanboy" <Sc*****@discus sions.microsoft .comwrote in message
news:70******** *************** ***********@mic rosoft.com...
Guyz,

Whatever happened to the 'Index' property for a control, that used to be
present in
VB 3.0 / 4.0 / 5.0 / 6.0 and which now seems to be missing from VBE 2005?

I need to be able to make 4 command buttons behave in the same way, the
'Index'
property indicating which command button I clicked on.

The 'Index' property is an useful time saver because it saves me making
copies of
the same code to the other command buttons and I needed all command
buttons
to behave in exactly the same way.

How do I accomplish this in VBE 2005? Thanks in advance.
SB


Jan 29 '07 #3


"Scanboy" wrote:
Rob,

Thanks! I have had a look around for control arrays in the VBE help system,
and
found out why. Event handlers made the use of control arrays redundant.

Thanks for introducing me to 'AddHandler', 'RemoveHandler' , 'DirectCast'. I
have
just looked at the 'Control Arrays For Visual Basic 6.0 Users' page.

Would the following code equally work as well?

Private Sub Buttons_Clicked (ByVal Sender As System.Object, _
ByVal SysEvntArgs As System.EventArg s) Handles Button1.Click,
Button2.Click, _
Button3.Click, Button4.Click
Select Case DirectCast(Send er, Button).Name
Case Button1.Name
MsgBox("You clicked on the first button!")
Case Button2.Name
MsgBox("You clicked on the second button!")
Case Button3.Name
MsgBox("You clicked on the third button!")
Case Button4.Name
MsgBox("You clicked on the fourth button!")
End Select
End Sub
I am pleased to be able to report that the code does work perfectly well!!!
:)
>
SB
-----------------------------------------------------------------------------------------------
"RobinS" wrote:
I'm sorry to tell you this, but control arrays have left the building.
Disappointing, isn't it?

If you want a bunch of buttons to perform the same event, just add your own
event handlers for them in your Form_Load event:

AddHandler myButton1.Click , DoThisForAllOfT hem
AddHandler myButton2.Click , DoThisForAllOfT hem
AddHandler myButton3.Click , DoThisForAllOfT hem
AddHandler myButton4.Click , DoThisForAllOfT hem
AddHandler myButton5.Click , DoThisForAllOfT hem

If you want to know which button invoked the click, you can probably do it
some fancy way (Reflection comes to mind), but I just put some identifier
in the [Tag] property for each button and check that like this:

Private Sub DoThisForAllOfT hem(ByVal sender as Object, ByVal e as
EventArgs)
Dim theButton As Button = DirectCast(send er, Button)
Select Case theButton.Tag
Case "1"
GoToSchool
Case "2"
GoToWork
Case "3"
GoShopping
Case "4"
GoToDinner
Case "5"
GoDrinking
End Select
End Sub

Be sure your buttons have a tag in them, if it is blank, this will throw a
NullException.

Robin S.
-------------------------------------------
"Scanboy" <Sc*****@discus sions.microsoft .comwrote in message
news:70******** *************** ***********@mic rosoft.com...
Guyz,
>
Whatever happened to the 'Index' property for a control, that used to be
present in
VB 3.0 / 4.0 / 5.0 / 6.0 and which now seems to be missing from VBE 2005?
>
I need to be able to make 4 command buttons behave in the same way, the
'Index'
property indicating which command button I clicked on.
>
The 'Index' property is an useful time saver because it saves me making
copies of
the same code to the other command buttons and I needed all command
buttons
to behave in exactly the same way.
>
How do I accomplish this in VBE 2005? Thanks in advance.
>
>
SB
Jan 29 '07 #4
It would work just as well (and does, as you reported). Putting all the
buttons
on the Handles clause works okay, but may cause you problems if you add or
remove any buttons. You may not remember to add them to the Handles
clause (on my Visual Studio, that would be so far out to the right, I
wouldn't
see it), or remove any if you delete the button.

Robin S.
-------------------------------------------
"Scanboy" <Sc*****@discus sions.microsoft .comwrote in message
news:EE******** *************** ***********@mic rosoft.com...
Rob,

Thanks! I have had a look around for control arrays in the VBE help
system,
and
found out why. Event handlers made the use of control arrays redundant.

Thanks for introducing me to 'AddHandler', 'RemoveHandler' , 'DirectCast'.
I
have
just looked at the 'Control Arrays For Visual Basic 6.0 Users' page.

Would the following code equally work as well?

Private Sub Buttons_Clicked (ByVal Sender As System.Object, _
ByVal SysEvntArgs As System.EventArg s) Handles Button1.Click,
Button2.Click, _
Button3.Click, Button4.Click
Select Case DirectCast(Send er, Button).Name
Case Button1.Name
MsgBox("You clicked on the first button!")
Case Button2.Name
MsgBox("You clicked on the second button!")
Case Button3.Name
MsgBox("You clicked on the third button!")
Case Button4.Name
MsgBox("You clicked on the fourth button!")
End Select
End Sub
SB
-----------------------------------------------------------------------------------------------
"RobinS" wrote:
>I'm sorry to tell you this, but control arrays have left the building.
Disappointin g, isn't it?

If you want a bunch of buttons to perform the same event, just add your
own
event handlers for them in your Form_Load event:

AddHandler myButton1.Click , DoThisForAllOfT hem
AddHandler myButton2.Click , DoThisForAllOfT hem
AddHandler myButton3.Click , DoThisForAllOfT hem
AddHandler myButton4.Click , DoThisForAllOfT hem
AddHandler myButton5.Click , DoThisForAllOfT hem

If you want to know which button invoked the click, you can probably do
it
some fancy way (Reflection comes to mind), but I just put some
identifier
in the [Tag] property for each button and check that like this:

Private Sub DoThisForAllOfT hem(ByVal sender as Object, ByVal e as
EventArgs)
Dim theButton As Button = DirectCast(send er, Button)
Select Case theButton.Tag
Case "1"
GoToSchool
Case "2"
GoToWork
Case "3"
GoShopping
Case "4"
GoToDinner
Case "5"
GoDrinking
End Select
End Sub

Be sure your buttons have a tag in them, if it is blank, this will throw
a
NullExceptio n.

Robin S.
-------------------------------------------
"Scanboy" <Sc*****@discus sions.microsoft .comwrote in message
news:70******* *************** ************@mi crosoft.com...
Guyz,

Whatever happened to the 'Index' property for a control, that used to
be
present in
VB 3.0 / 4.0 / 5.0 / 6.0 and which now seems to be missing from VBE
2005?

I need to be able to make 4 command buttons behave in the same way,
the
'Index'
property indicating which command button I clicked on.

The 'Index' property is an useful time saver because it saves me
making
copies of
the same code to the other command buttons and I needed all command
buttons
to behave in exactly the same way.

How do I accomplish this in VBE 2005? Thanks in advance.
SB



Jan 29 '07 #5


"RobinS" wrote:
It would work just as well (and does, as you reported). Putting all the
buttons
on the Handles clause works okay, but may cause you problems if you add or
remove any buttons. You may not remember to add them to the Handles
clause (on my Visual Studio, that would be so far out to the right, I
wouldn't
see it), or remove any if you delete the button.

Robin S.
OK. Thanks for the tip.
-------------------------------------------
"Scanboy" <Sc*****@discus sions.microsoft .comwrote in message
news:EE******** *************** ***********@mic rosoft.com...
Rob,

Thanks! I have had a look around for control arrays in the VBE help
system,
and
found out why. Event handlers made the use of control arrays redundant.

Thanks for introducing me to 'AddHandler', 'RemoveHandler' , 'DirectCast'.
I
have
just looked at the 'Control Arrays For Visual Basic 6.0 Users' page.

Would the following code equally work as well?

Private Sub Buttons_Clicked (ByVal Sender As System.Object, _
ByVal SysEvntArgs As System.EventArg s) Handles Button1.Click,
Button2.Click, _
Button3.Click, Button4.Click
Select Case DirectCast(Send er, Button).Name
Case Button1.Name
MsgBox("You clicked on the first button!")
Case Button2.Name
MsgBox("You clicked on the second button!")
Case Button3.Name
MsgBox("You clicked on the third button!")
Case Button4.Name
MsgBox("You clicked on the fourth button!")
End Select
End Sub
SB
-----------------------------------------------------------------------------------------------
"RobinS" wrote:
I'm sorry to tell you this, but control arrays have left the building.
Disappointing, isn't it?

If you want a bunch of buttons to perform the same event, just add your
own
event handlers for them in your Form_Load event:

AddHandler myButton1.Click , DoThisForAllOfT hem
AddHandler myButton2.Click , DoThisForAllOfT hem
AddHandler myButton3.Click , DoThisForAllOfT hem
AddHandler myButton4.Click , DoThisForAllOfT hem
AddHandler myButton5.Click , DoThisForAllOfT hem

If you want to know which button invoked the click, you can probably do
it
some fancy way (Reflection comes to mind), but I just put some
identifier
in the [Tag] property for each button and check that like this:

Private Sub DoThisForAllOfT hem(ByVal sender as Object, ByVal e as
EventArgs)
Dim theButton As Button = DirectCast(send er, Button)
Select Case theButton.Tag
Case "1"
GoToSchool
Case "2"
GoToWork
Case "3"
GoShopping
Case "4"
GoToDinner
Case "5"
GoDrinking
End Select
End Sub

Be sure your buttons have a tag in them, if it is blank, this will throw
a
NullException.

Robin S.
-------------------------------------------
"Scanboy" <Sc*****@discus sions.microsoft .comwrote in message
news:70******** *************** ***********@mic rosoft.com...
Guyz,

Whatever happened to the 'Index' property for a control, that used to
be
present in
VB 3.0 / 4.0 / 5.0 / 6.0 and which now seems to be missing from VBE
2005?

I need to be able to make 4 command buttons behave in the same way,
the
'Index'
property indicating which command button I clicked on.

The 'Index' property is an useful time saver because it saves me
making
copies of
the same code to the other command buttons and I needed all command
buttons
to behave in exactly the same way.

How do I accomplish this in VBE 2005? Thanks in advance.
SB


Jan 29 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1680
by: Dean Slindee | last post by:
Does anybody know to whom I can send this letter so that it hits home before Visual Studio 2005 goes production? Dear Microsoft Visual Studio 2005 developers, This is a request for you to change four of the most basic controls to improve them and make them more consistent amongst themselves.
2
6133
by: Maileen | last post by:
Hi, I've create an application which includes : - a toolstrip - a toolstripmenu - several toolstripmenuitem(s) so, now i have a menu like that : -File
3
4798
by: xycos | last post by:
Hello. I apologize for asking this question as the information I need is availible via the MSDN library, however I cannot seemt o understand what I need to do, so I'm asking here. I have created application settings in Visual Studio (right-click on the project, go to the settings tab, etc.) and have associated each of these settings with a property on a form. This seems to be working right (i.e. if I edit the default value of a setting,...
3
1121
by: =?Utf-8?B?U2NhbmJveQ==?= | last post by:
Guyz, Whatever happened to the 'Index' property for a control, that used to be present in VB 3.0 / 4.0 / 5.0 / 6.0 and which now seems to be missing from VBE 2005? I need to be able to make 4 command buttons behave in the same way, the 'Index' property indicating which command button I clicked on.
0
9686
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10279
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7819
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5855
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.