473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

85 Identical Procedures Are Having An Orgy In My Program. Could You Help?

Having just figured out the function of the *sender* argument in control
events, I now have 85 labelX_Click procedures that perform the exact same
function: Call ColorChange(sender). That's it.

I could make one procedure to handle them all, of the form:

Sub GUITileProc([arguments here]) Handles Label1.Click, Label2.Click... all
the way to Label85.Click.

But that would be really messy, and if there's one thing I hate, it's messy
code. Is there any way that I could group those events together elsewhere,
under a "group" name, then just say that GUITileProc "Handles
GUITileClicks"?

It'd make future code modification that much easier.
Nov 21 '05 #1
2 993
You could run a loop through the controls for that form and if the .Name
field matches (use regex or just an instr if you wish) then do an
for each myControl in Controls
if (instr(myControl.Name, "MyLabelName_")) then
AddHandler myControl.Click, New EventHandler(AddressOf GUITileProf)
end if
next

"Confessor" <in*****@reply.to.group> wrote in message
news:Xn*********************************@130.81.64 .196...
Having just figured out the function of the *sender* argument in control
events, I now have 85 labelX_Click procedures that perform the exact same
function: Call ColorChange(sender). That's it.

I could make one procedure to handle them all, of the form:

Sub GUITileProc([arguments here]) Handles Label1.Click, Label2.Click... all the way to Label85.Click.

But that would be really messy, and if there's one thing I hate, it's messy code. Is there any way that I could group those events together elsewhere,
under a "group" name, then just say that GUITileProc "Handles
GUITileClicks"?

It'd make future code modification that much easier.

Nov 21 '05 #2
Or if all the labels on your form (tab page control, user control, etc) are
using the same event handler then you could do:

' pass in your form, tab page, user control, etc as parent
Private Sub AddAllHandlers(Parent As Control)
For Each Ctrl In Parent.Controls
If TypeOf Ctrl Is Label Then
AddHandler Ctrl.Click, AddressOf GUITileProf
End If
Next Ctrl

Imran.

"CJ Taylor" <cege [ahh ttt] tavayn wooohooo hooo ohhh com> wrote in message
news:OR**************@TK2MSFTNGP10.phx.gbl...
You could run a loop through the controls for that form and if the .Name
field matches (use regex or just an instr if you wish) then do an
for each myControl in Controls
if (instr(myControl.Name, "MyLabelName_")) then
AddHandler myControl.Click, New EventHandler(AddressOf GUITileProf)
end if
next

"Confessor" <in*****@reply.to.group> wrote in message
news:Xn*********************************@130.81.64 .196...
Having just figured out the function of the *sender* argument in control
events, I now have 85 labelX_Click procedures that perform the exact same
function: Call ColorChange(sender). That's it.

I could make one procedure to handle them all, of the form:

Sub GUITileProc([arguments here]) Handles Label1.Click, Label2.Click...

all
the way to Label85.Click.

But that would be really messy, and if there's one thing I hate, it's

messy
code. Is there any way that I could group those events together
elsewhere,
under a "group" name, then just say that GUITileProc "Handles
GUITileClicks"?

It'd make future code modification that much easier.


Nov 21 '05 #3

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

Similar topics

10
by: John A Fotheringham | last post by:
I'm trying to write a procedure that having created a new database, will then create within that new database all the tables and procedures that go with it. In doing this I'm hitting the problem...
4
by: HeadScratcher | last post by:
We have written an application which splits up our customers data into their individual databases. The structure of the databases is the same. Is it better to create the same stored procedures in...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
2
by: Quinnie | last post by:
Hi, I have a homework assignment that I'm so confused and really need help with. Here's the description, any help would be appreciated. Thanks! Assume we have a statically-scoped language...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
4
by: nishi57 | last post by:
I hope I can get some help regarding this issue, which has been going on for a while. I have a desktop user who is having problem running "Stored Procedures". The DB2 Connect application works fine...
0
by: vanesa | last post by:
Hi, In a client we must begin to program many stored procedures of DB2. The following doubts arise to me that I raise you to see if you can help me: 1. From a point of view of the programming:...
5
by: patrick.cc.choi | last post by:
Hi all, In Oracle stored procedures, you can declare sub-procedures to help modularize your code... i.e. CREATE OR REPLACE PROCEDURE myProcedure is PROCEDURE b (field1 INTEGER, field2...
14
by: jehugaleahsa | last post by:
Hello: I am working with Oracle .NET Stored Procedures. I would like to know how to return the results of a SELECT statement. I have tried returning a OracleRefCursor and a DataTable, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.