473,404 Members | 2,174 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,404 software developers and data experts.

Controlling Events

Good evening all,

I am trying to set-up an array of procedures, which HELP informs me is
impossible, so as a secondary idea I thought I could set up an array of
initializing an event, which I also seem unable to do.

What I am basically trying to do, is set-up an array that can somehow
initialize procedures, as I have nearly two-hundred panels I need to
cycle through and I don't want to use an extended IF Statement.

Any help you may be able to provide would be much appreciated. Please
see the example below of what I am basically trying to do.

Yours sincerely,

Brent McIntyre
EXAMPLE of current set-up

If Selection_Variable = 1 then
Procedure_Panel_One_Selected
Else
If Selection_Variable = 2 then
Procedure_Panel_Two_Selected
Else

etc....
End If
End If

EXAMPLE of what I would like

Procedure_Panel_Selection(1) ' Which would the run
Procedure_Panel_One_Selected

This takes a lot less code and can allow me to make my code easier for
others to read and understand.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
6 1181
Hi Brent,

A procedure can be called indirectly by using a Delegate. [Simplified, a
Delegate is a fancy function pointer]. It would be easy to utilise an array of
Delegates. There would still be the requitrement of setting this array up This
itself may be stuck in a loop, perhaps. Good things to learn about, are
Delegates.

However, another possibility, and easier to use, is CallByName() to which
you give the object and the name of the method to call. You might find it
useful to change "Proc_Panel_One_Sel" to "Proc_Panel_1_Sel". Then you can
have:

Dim sProcSel As String _
= "Procedure_Panel_" & Selection_Variable & "_Selected"
CallByName (Me, sProcSel, CallType.Method, Nothing)

I'm not sure whether the Me and the Nothing are applicable for you, but
have a play with it.

Regards,
Fergus
Nov 20 '05 #2
Cor
Hi Brent,
I dont think you mean it but your example what you want, looks exact as case
select.
\\\
case select Procedure_Panel_Selection
case 1
Procedure_Panel_One_Selected
case 2
Procedure_Panel_Two_Selected
end select
///
And to extend it with some events
\\\
Private Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
Dim btn As Button = DirectCast(sender, Button)
Select Case btn.Name
Case "Button1"
Procedure_Panel_One_Selected
Case "Button2"
Procedure_Panel_Two_Selected
End Select
///
Of course I mis something but, for me it looks like that.
Cor
Nov 20 '05 #3
Brent,
As Furgus suggested the array of Delegates is how you get an array of
procedures.

Delegate Sub PanelSelected()

Dim Procedure_Panel_Selection() As PanelSelected = _
{ _
AddressOf Procedure_Panel_One_Selected, _
AddressOf Procedure_Panel_Two_Selected, _
AddressOf Procedure_Panel_Three_Selected _
}

Remember that arrays are zero based:

Procedure_Panel_Selection(0).Invoke()

Will execute Procedure_Panel_One_Selected.

Note:
If Selection_Variable = 1 then
Procedure_Panel_One_Selected
Else
If Selection_Variable = 2 then
Procedure_Panel_Two_Selected
Else

etc....
End If
End If
Also Select Case or ElseIf both simplify your selection statement.

Select Case Selection_Variable
Case 1
Procedure_Panel_One_Selected
Case 2
Procedure_Panel_Two_Selected
End Select

If Selection_Variable = 1 Then
Procedure_Panel_One_Selected
ElseIf Selection_Variable = 2 Then
Procedure_Panel_Two_Selected
ElseIf Selection_Variable = 3 Then
Procedure_Panel_Three_Selected
End if

However my concern is you really need Polymorphism. Is the initialization
code largely the same for each panel or unique for each panel?

I would consider creating one or more new classes that are derived from
Panel that has the initialization code in the constructor of this new class.
Depending on how unique this initialization code is, I would have custom
properties, a custom event, or multiple derived classes for the unique code.
Applying OOP principles to simplify the code.

Hope this helps
Jay
"Brent McIntyre" <br************@aep.salvationarmy.org> wrote in message
news:e$**************@tk2msftngp13.phx.gbl... Good evening all,

I am trying to set-up an array of procedures, which HELP informs me is
impossible, so as a secondary idea I thought I could set up an array of
initializing an event, which I also seem unable to do.

What I am basically trying to do, is set-up an array that can somehow
initialize procedures, as I have nearly two-hundred panels I need to
cycle through and I don't want to use an extended IF Statement.

Any help you may be able to provide would be much appreciated. Please
see the example below of what I am basically trying to do.

Yours sincerely,

Brent McIntyre
EXAMPLE of current set-up

If Selection_Variable = 1 then
Procedure_Panel_One_Selected
Else
If Selection_Variable = 2 then
Procedure_Panel_Two_Selected
Else

etc....
End If
End If

EXAMPLE of what I would like

Procedure_Panel_Selection(1) ' Which would the run
Procedure_Panel_One_Selected

This takes a lot less code and can allow me to make my code easier for
others to read and understand.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #4
Brent McIntyre <br************@aep.salvationarmy.org> scripsit:
I am trying to set-up an array of procedures, which HELP informs me is
impossible, so as a secondary idea I thought I could set up an array of
initializing an event, which I also seem unable to do.

What I am basically trying to do, is set-up an array that can somehow
initialize procedures, as I have nearly two-hundred panels I need to
cycle through and I don't want to use an extended IF Statement.

Any help you may be able to provide would be much appreciated. Please
see the example below of what I am basically trying to do.


Why not loop through the panels and add a shared event handler using
'AddHandler'? In the event handler you can determine which control the
event belongs to by looking at the 'sender' parameter.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Good morning all,

Thank you very much for all your ideas ! I will review them tonight.

Yours sincerely,

Brent McIntyre

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #6
Good evening all,

Thanks to everyone that helped me out, Fergus, Cor, Jay and Herfried.
In the end I used Delegates as described by Furgus and Jay, as it
provided me with not only a new idea, but a great way of reducing code
and increasing simplicity so that anyone can modify what I have now
set-up.

Thank you all for your great ideas, if only the in-built help could
offer solutions rather than saying what isn't possible.

Yours sincerely,

Brent McIntyre

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7

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

Similar topics

0
by: Ayende Rahien | last post by:
How do I catch events from a web browser hosted in my application? I host it by adding a reference to SHDocVw and then adding it to my form. Right now I can tell it to fetch a page using...
3
by: Scott M | last post by:
Hi, I am currently trying to write a simple game using vb.net the form I am working on is 800*600 (this is set as the maximum size) and autoscroll is set to true. The user moves around the...
0
by: Ayende Rahien | last post by:
How do I catch events from a web browser hosted in my application? I host it by adding a reference to SHDocVw and then adding it to my form. Right now I can tell it to fetch a page using...
2
by: ApexData | last post by:
Hello In order to control keyboard keystrokes in my application, I use the KeyPreview=Yes, OnKeyDown Events of every Form with great success. HOWEVER, these events are not available in REPORTS,...
4
by: Joergen Bech | last post by:
Just out of curiosity: What is your favorite method of making sure that anything that happens on a form, only happens in response to a single, external event? Take the example below. I have made...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.