Hello,
I am wondering if it is possible to pass a procedure name to another proc.
I have been looking into delegates, but cannot seem to get the code correct.
Basically what I have is a proc to add handlers to various controls on a
form. basically each control would get mostly the same handlers, but there
is a particular handler that would vary based on the parent on the control
in question. What I would like to do is something like below. The problem
is in the form load - calling the routine and passing it the name of another
proc.
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'add panel 1 handlers
AddHandlers (pnlOne, ProcOne)
'add panel 2 handlers
AddHandlers (pnlTwo, ProcTwo)
'add panel 3 handlers
AddHandlers (pnlThree, ProcThree)
'add panel 4 handlers
AddHandlers (pnlFour, ProcFour)
End Sub
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as ?????)
'add the proper event handlers to each control on a form
'ChangeProc would be either ProcOne, ProcTwo, ProcThree or ProcFour
' depending on what was passed in
Dim ctrlCur As Control
For Each ctrlCur In ctrlIn.Controls
If (TypeOf ctrlCur Is TextBox) Then
AddHandler ctrlCur.Enter, AddressOf txtBoxEnter
AddHandler ctrlCur.Leave, AddressOf txtBoxLeave
AddHandler ctrlCur.TextChanged, AddressOf ChangeProc
'etc...
End If
Next
End Sub
(NOTE the ProcOne etc code is more complex, this is just an example)
Private Sub ProcOne
cmdOne.Enabled = True
cmdTwo.Enabled = False
cmdThree.Enabled = False
cmdFour.Enabled = False
End Sub
Private Sub ProcTwo
cmdOne.Enabled = False
cmdTwo.Enabled = True
cmdThree.Enabled = False
cmdFour.Enabled = False
End Sub
Private Sub ProcThree
cmdOne.Enabled = False
cmdTwo.Enabled = False
cmdThree.Enabled = Three
cmdFour.Enabled = False
End Sub
Private Sub ProcFour
cmdOne.Enabled = False
cmdTwo.Enabled = False
cmdThree.Enabled = False
cmdFour.Enabled = True
End Sub 5 1418
Mike,
See this nice test from Jay where he shows that using a column as indexer is
the fastest to index a datarow/dataview item. However that is not important
for your question. In that test he uses (as I understand you well( what you
ask. http://groups-beta.google.com/group/...505bbbff764679
Cor
"Mike Hoff" <mi**@home.com> I am wondering if it is possible to pass a procedure name to another proc. I have been looking into delegates, but cannot seem to get the code correct. Basically what I have is a proc to add handlers to various controls on a form. basically each control would get mostly the same handlers, but there is a particular handler that would vary based on the parent on the control in question. What I would like to do is something like below. The problem is in the form load - calling the routine and passing it the name of another proc.
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'add panel 1 handlers AddHandlers (pnlOne, ProcOne)
'add panel 2 handlers AddHandlers (pnlTwo, ProcTwo)
'add panel 3 handlers AddHandlers (pnlThree, ProcThree)
'add panel 4 handlers AddHandlers (pnlFour, ProcFour)
End Sub
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as ?????) 'add the proper event handlers to each control on a form 'ChangeProc would be either ProcOne, ProcTwo, ProcThree or ProcFour ' depending on what was passed in
Dim ctrlCur As Control
For Each ctrlCur In ctrlIn.Controls
If (TypeOf ctrlCur Is TextBox) Then AddHandler ctrlCur.Enter, AddressOf txtBoxEnter AddHandler ctrlCur.Leave, AddressOf txtBoxLeave AddHandler ctrlCur.TextChanged, AddressOf ChangeProc
'etc...
End If Next
End Sub
(NOTE the ProcOne etc code is more complex, this is just an example)
Private Sub ProcOne
cmdOne.Enabled = True cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcTwo
cmdOne.Enabled = False cmdTwo.Enabled = True cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcThree
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = Three cmdFour.Enabled = False
End Sub
Private Sub ProcFour
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = True
End Sub
"Mike Hoff" <mi**@home.com> schrieb: I am wondering if it is possible to pass a procedure name to another proc. I have been looking into delegates, but cannot seem to get the code correct. Basically what I have is a proc to add handlers to various controls on a form. basically each control would get mostly the same handlers, but there is a particular handler that would vary based on the parent on the control in question. What I would like to do is something like below. The problem is in the form load - calling the routine and passing it the name of another proc.
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'add panel 1 handlers AddHandlers (pnlOne, ProcOne)
'add panel 2 handlers AddHandlers (pnlTwo, ProcTwo)
'add panel 3 handlers AddHandlers (pnlThree, ProcThree)
'add panel 4 handlers AddHandlers (pnlFour, ProcFour)
End Sub
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as ?????)
'As [Delegate]'...
\\\
AddHandler ctrIn.Enter, ChangeProc
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Mike,
In addition to the other comments.
You want to pass the address of the proc to AddHandlers, then you simply
want to use this address on AddHandler.
So when you call AddHandlers you need to use AddressOf: 'add panel 1 handlers AddHandlers (pnlOne, AddressOf ProcOne)
With Option Strict On, you need the specific type of Handler being passed,
TextChanged matches EventHandler, so that is the one to use.
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as EventHandler) 'add the proper event handlers to each control on a form
Seeing as ChangeProc is already an address, you can simply use it: AddHandler ctrlCur.TextChanged, ChangeProc
Hope this helps
Jay
"Mike Hoff" <mi**@home.com> wrote in message
news:7D*****************@fe03.lga... Hello,
I am wondering if it is possible to pass a procedure name to another proc. I have been looking into delegates, but cannot seem to get the code correct. Basically what I have is a proc to add handlers to various controls on a form. basically each control would get mostly the same handlers, but there is a particular handler that would vary based on the parent on the control in question. What I would like to do is something like below. The problem is in the form load - calling the routine and passing it the name of another proc.
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'add panel 1 handlers AddHandlers (pnlOne, ProcOne)
'add panel 2 handlers AddHandlers (pnlTwo, ProcTwo)
'add panel 3 handlers AddHandlers (pnlThree, ProcThree)
'add panel 4 handlers AddHandlers (pnlFour, ProcFour)
End Sub
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as ?????) 'add the proper event handlers to each control on a form 'ChangeProc would be either ProcOne, ProcTwo, ProcThree or ProcFour ' depending on what was passed in
Dim ctrlCur As Control
For Each ctrlCur In ctrlIn.Controls
If (TypeOf ctrlCur Is TextBox) Then AddHandler ctrlCur.Enter, AddressOf txtBoxEnter AddHandler ctrlCur.Leave, AddressOf txtBoxLeave AddHandler ctrlCur.TextChanged, AddressOf ChangeProc
'etc...
End If Next
End Sub
(NOTE the ProcOne etc code is more complex, this is just an example)
Private Sub ProcOne
cmdOne.Enabled = True cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcTwo
cmdOne.Enabled = False cmdTwo.Enabled = True cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcThree
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = Three cmdFour.Enabled = False
End Sub
Private Sub ProcFour
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = True
End Sub
Thanks for the responses. This is exactly what I needed and is working
perfectly!
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u%****************@tk2msftngp13.phx.gbl... Mike, In addition to the other comments.
You want to pass the address of the proc to AddHandlers, then you simply want to use this address on AddHandler.
So when you call AddHandlers you need to use AddressOf:
'add panel 1 handlers AddHandlers (pnlOne, AddressOf ProcOne)
With Option Strict On, you need the specific type of Handler being passed, TextChanged matches EventHandler, so that is the one to use.
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as EventHandler) 'add the proper event handlers to each control on a form
Seeing as ChangeProc is already an address, you can simply use it: AddHandler ctrlCur.TextChanged, ChangeProc
Hope this helps Jay
"Mike Hoff" <mi**@home.com> wrote in message news:7D*****************@fe03.lga... Hello,
I am wondering if it is possible to pass a procedure name to another
proc. I have been looking into delegates, but cannot seem to get the code correct. Basically what I have is a proc to add handlers to various controls on a form. basically each control would get mostly the same handlers, but there is a particular handler that would vary based on the parent on the
control in question. What I would like to do is something like below. The problem is in the form load - calling the routine and passing it the name of another proc.
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'add panel 1 handlers AddHandlers (pnlOne, ProcOne)
'add panel 2 handlers AddHandlers (pnlTwo, ProcTwo)
'add panel 3 handlers AddHandlers (pnlThree, ProcThree)
'add panel 4 handlers AddHandlers (pnlFour, ProcFour)
End Sub
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as ?????) 'add the proper event handlers to each control on a form 'ChangeProc would be either ProcOne, ProcTwo, ProcThree or
ProcFour ' depending on what was passed in
Dim ctrlCur As Control
For Each ctrlCur In ctrlIn.Controls
If (TypeOf ctrlCur Is TextBox) Then AddHandler ctrlCur.Enter, AddressOf txtBoxEnter AddHandler ctrlCur.Leave, AddressOf txtBoxLeave AddHandler ctrlCur.TextChanged, AddressOf ChangeProc
'etc...
End If Next
End Sub
(NOTE the ProcOne etc code is more complex, this is just an example)
Private Sub ProcOne
cmdOne.Enabled = True cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcTwo
cmdOne.Enabled = False cmdTwo.Enabled = True cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcThree
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = Three cmdFour.Enabled = False
End Sub
Private Sub ProcFour
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = True
End Sub
Thanks for the responses. This is exactly what I needed and is working
perfectly!
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u%****************@tk2msftngp13.phx.gbl... Mike, In addition to the other comments.
You want to pass the address of the proc to AddHandlers, then you simply want to use this address on AddHandler.
So when you call AddHandlers you need to use AddressOf:
'add panel 1 handlers AddHandlers (pnlOne, AddressOf ProcOne)
With Option Strict On, you need the specific type of Handler being passed, TextChanged matches EventHandler, so that is the one to use.
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as EventHandler) 'add the proper event handlers to each control on a form
Seeing as ChangeProc is already an address, you can simply use it: AddHandler ctrlCur.TextChanged, ChangeProc
Hope this helps Jay
"Mike Hoff" <mi**@home.com> wrote in message news:7D*****************@fe03.lga... Hello,
I am wondering if it is possible to pass a procedure name to another
proc. I have been looking into delegates, but cannot seem to get the code correct. Basically what I have is a proc to add handlers to various controls on a form. basically each control would get mostly the same handlers, but there is a particular handler that would vary based on the parent on the
control in question. What I would like to do is something like below. The problem is in the form load - calling the routine and passing it the name of another proc.
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'add panel 1 handlers AddHandlers (pnlOne, ProcOne)
'add panel 2 handlers AddHandlers (pnlTwo, ProcTwo)
'add panel 3 handlers AddHandlers (pnlThree, ProcThree)
'add panel 4 handlers AddHandlers (pnlFour, ProcFour)
End Sub
Public Sub AddHandlers(ByVal ctrlIn As Control, ChangeProc as ?????) 'add the proper event handlers to each control on a form 'ChangeProc would be either ProcOne, ProcTwo, ProcThree or
ProcFour ' depending on what was passed in
Dim ctrlCur As Control
For Each ctrlCur In ctrlIn.Controls
If (TypeOf ctrlCur Is TextBox) Then AddHandler ctrlCur.Enter, AddressOf txtBoxEnter AddHandler ctrlCur.Leave, AddressOf txtBoxLeave AddHandler ctrlCur.TextChanged, AddressOf ChangeProc
'etc...
End If Next
End Sub
(NOTE the ProcOne etc code is more complex, this is just an example)
Private Sub ProcOne
cmdOne.Enabled = True cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcTwo
cmdOne.Enabled = False cmdTwo.Enabled = True cmdThree.Enabled = False cmdFour.Enabled = False
End Sub
Private Sub ProcThree
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = Three cmdFour.Enabled = False
End Sub
Private Sub ProcFour
cmdOne.Enabled = False cmdTwo.Enabled = False cmdThree.Enabled = False cmdFour.Enabled = True
End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stephen Williams |
last post by:
Hey i've got bunch of arrays of tick boxes, each array contains somewhere
between 5 and 20.
What I want to do is write a function that returns the captions of every
ticked tick box in an array...
|
by: Jeff Thur |
last post by:
I am running a SQL Stored Procedure that will give the
user a count of how many records are in the database as
per certain criteria.
I'm using the Execute Scalar Method.
I have no problem passing...
|
by: T.S.Negi |
last post by:
Dear Techies,
I making one stored procedure, which does some operation based on an
interface hash (#) table ---- name #mydata.
This stored has two section of code (seperated by parameter value...
|
by: Mark Dicken |
last post by:
Hi All
I have found the following Microsoft Technet 'Q'
Article :-
Q210368 -ACC2000: How to Pass an Array as an Argument to a Procedure
(I've also copied and pasted the whole contents into...
|
by: Zlatko Matić |
last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the...
|
by: Zlatko Matić |
last post by:
Hi everybody!
Recently I was struggling with client/server issues in MS Access/PostgreSQL
combination.
Although Access is intuitive and easy to use desktop database solution, many
problems...
|
by: Joseph Lu |
last post by:
Hi, all
I have a stored procedure created in SQL Server like the following
lines.
// stored proceudre code starts here
CREATE PROCEDURE sp_insertdata
@strdata varchar(250) ,
@rsult BIT...
|
by: tshad |
last post by:
I want to access multiple arguments based on name passed.
For example I have the following asp:textboxes:
BillingAddress1
BillingAddress2
BillingCity
ShippingAddress1
ShippingAddress2...
|
by: Afaque Khan |
last post by:
HI All,
I have a requirement, I need to pass table as IN parameter in the stored procedure. But when I do this it just says Table 'database.strtable' doesn't exist
.
Can you guys please advice...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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: 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...
| |