Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling a button/menu click from another sub

Posted on 2004-09-20
4
Medium Priority
?
716 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

704 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