calling sub question

D

djc

I have a subroutine that is used in a few places within a page. It is
declared with no parameters like so:

Sub subName()

End Sub

I would now also like to call this same sub from a button click using
OnClick or OnComand. However each of those require there own signature such
as:

Sub SubName(sender As Object, e As System.EventArgs) etc..

End Sub

If I don't have the right signiture I get a compile error. Then, if I add
the signature I get a compile error when this sub is called from other
places besides the button's event.

error with signature:
Argument not specified for parameter 'e' of 'Public Sub
ResetDynamicControls(Sender As Object, e As System.EventArgs)

error without signiture:
Method 'Public Sub ResetDynamicControls()' does not have the same signature
as delegate 'Delegate Sub EventHandler(sender As Object, e As
System.EventArgs)'

How can I use/call the same subroutine both from a button's event AND other
places such as within other subroutines?
 
B

Ben Lucas

Write a sub that does what you need to do. Call that sub from the event
handler. For example:

if your sub is:

Sub ResetDynamicControls()
//Code goes in here
End Sub

then your event handler looks like:

Sub Button_OnClick(sender As Object, e As System.EventArgs) etc..
ResetDynamicControls()
End Sub
 
G

Guest

I think the easiest way to resolve this is to place a call to the subroutine
"Subname" from inside the Sub that handles the button.Click event.

For example:

' This is linked to the button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Subname()
End Sub

' This is the original subroutine
Sub Subname()
....
End Sub

Ray
 
D

djc

Ahh. Yeah. Nice. Thanks!

Ben Lucas said:
Write a sub that does what you need to do. Call that sub from the event
handler. For example:

if your sub is:

Sub ResetDynamicControls()
//Code goes in here
End Sub

then your event handler looks like:

Sub Button_OnClick(sender As Object, e As System.EventArgs) etc..
ResetDynamicControls()
End Sub

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
 
D

djc

will do. Thank you.

Raymond U. Holder said:
I think the easiest way to resolve this is to place a call to the subroutine
"Subname" from inside the Sub that handles the button.Click event.

For example:

' This is linked to the button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Subname()
End Sub

' This is the original subroutine
Sub Subname()
...
End Sub

Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top