Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling a button/menu click from another sub

Posted on 2004-09-20
4
Medium Priority
?
725 Views
Last Modified: 2012-06-21
Hi,

In my code, I have a button (OK) that has code:

 Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
         ...
 End Sub


In another spot, I have an icon shortcut as well as a keypress that should trigger this code - but unlike in VB6, I can't just say Call cmdOK_click

It seems to want arguments...  However, I don't know what sender or e really are.  I found that if I use

Call cmdOK_Click("", e)

it accepts "" for sender, but I can't find any null-type expression to replace e with, (0, "", '', null, etc)

What do I need to do to trigger a _click event from another sub?

JP
0
Comment
Question by:gleznov
4 Comments
 

Author Comment

by:gleznov
ID: 12104791
OK I cheated - I put the code from the _click into it's own private sub, then just called it without the call command in both _click and the other routines.  However, I'd still like to know if there was an answer to my original question?

JP
0
 
LVL 2

Expert Comment

by:Mehrdad_Y
ID: 12104944
Hello, you have two ways:
1- cmdOk_Click(nothing, new System.EventArgs())
2- Me.cmdOK.PerformClick()
0
 
LVL 5

Assisted Solution

by:tzxie2000
tzxie2000 earned 500 total points
ID: 12104951
you can just call cmdOK_Click(Nothing, Nothing)
but you should not use object and e in cmdOK_Click
0
 
LVL 3

Accepted Solution

by:
imu79 earned 500 total points
ID: 12105290
It depends on what exactly you're trying to do. If you actually want to 'fire' the event, then you can call the PerformClick method of the button to raise the click event for the button. If you simply want to execute the code in the click event handler, you can directly call the procedure as mentioned in the previous to comments. A more cleaner solution would be to have your event handling procedure call another private procedure and whenever you want to execute the event handling code, you can directly call the private procedure and not worry about passing parameters into the event handing procedure.

Something like this:

Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        ClickEventProcedure( )
End Sub

Private Sub ClickEventProcedure( )
    ' click event handing code...
End Sub

Private Sub AnotherSub( )
    ClickEventProcedure( )
End Sub

Ofcourse, your click event handler is using the sender and the event arguments for whatever processing you're doing, you would need to pass them in to this private event procedure. But that would defeat the whole purpose of not having to pass the event arguments. I guess in the end it all boils down what exactly is the purpose of executing the  event handling code - based on that you can decide which method best suites your requirements.

hope that helps..
Imran.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question