PC Review


Reply
Thread Tools Rate Thread

Controlling Events

 
 
Brent McIntyre
Guest
Posts: n/a
 
      5th Oct 2003
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!
 
Reply With Quote
 
 
 
 
Fergus Cooney
Guest
Posts: n/a
 
      5th Oct 2003
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


 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      5th Oct 2003
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


 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      5th Oct 2003
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" <(E-Mail Removed)> wrote in message
news:e$(E-Mail Removed)...
> 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!



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      5th Oct 2003
Brent McIntyre <(E-Mail Removed)> 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>
 
Reply With Quote
 
Brent McIntyre
Guest
Posts: n/a
 
      6th Oct 2003
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!
 
Reply With Quote
 
Brent McIntyre
Guest
Posts: n/a
 
      6th Oct 2003
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling flicker in mouse move events John Coleman Microsoft Excel Programming 1 6th Oct 2005 03:25 AM
controlling from xls , word events jlsainz Microsoft Excel Programming 0 18th Sep 2004 11:06 PM
Controlling Explorer - Catching events Ayende Rahien Microsoft Dot NET Framework Forms 0 1st Dec 2003 11:41 PM
Controlling Explorer - Catching events Ayende Rahien Microsoft Dot NET 0 1st Dec 2003 11:41 PM
Controlling wheelmouse events in a combo box... Geoff Taylor Microsoft Access Form Coding 1 24th Sep 2003 12:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:00 AM.