• 0

[VB.NET] Calling Subroutines


Question

I have a few bits of code in a few subroutines. One of them is like this:

Private Sub RestartExplorer(ByVal sender As System.Object, ByVal e As System.EventArgs)
        System.Diagnostics.Process.Start("tskill.exe", "explorer")
        System.Diagnostics.Process.Start("explorer.exe")
End Sub

Now, when a user clicks a button, I want it to execute that sub. So when I double-click the button in the form editor and type 'RestartExplorer()', it tells me something about "Argument not specified for parameter 'e' of 'Private Sub RestartExplorer(sender As Object, e As System.EventArgs)". If I remove that whole "ByVal sender" stuff, it works, but then the function cant be called in the context menu for the tray icon. How can I call this function while keeping the "ByVal sender" stuff? :wacko:

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0
I have a few bits of code in a few subroutines.  One of them is like this:

Private Sub RestartExplorer(ByVal sender As System.Object, ByVal e As System.EventArgs)
 ? ? ? ?System.Diagnostics.Process.Start("tskill.exe", "explorer")
 ? ? ? ?System.Diagnostics.Process.Start("explorer.exe")
End Sub

Now, when a user clicks a button, I want it to execute that sub.  So when I double-click the button in the form editor and type 'RestartExplorer()', it tells me something about "Argument not specified for parameter 'e' of 'Private Sub RestartExplorer(sender As Object, e As System.EventArgs)".  If I remove that whole "ByVal sender" stuff, it works, but then the function cant be called in the context menu for the tray icon.  How can I call this function while keeping the "ByVal sender&quo:wacko:f? :wacko:

But why you write your function like that, you are not using the sender nor the e arguments in that sub, why you did not write it as:

Private Sub RestartExplorer()
        System.Diagnostics.Process.Start("tskill.exe", "explorer")
        System.Diagnostics.Process.Start("explorer.exe")
End Sub

Link to comment
Share on other sites

  • 0
But why you write your function like that, you are not using the sender nor the e arguments in that sub, why you did not write it as:

Private Sub RestartExplorer()
        System.Diagnostics.Process.Start("tskill.exe", "explorer")
        System.Diagnostics.Process.Start("explorer.exe")
End Sub

It's an event handler for a menu event. It has to match the delegate signature.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.