What is alternative to 'Run' command

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hi There,

I have been using VB in Excel and when I want to get one of my other subs to run I would write Run("MySub").

I am now using VB in VS2005 and the run command doesn't seem to want to play ball.

What do I need to write?

Thanks

John
 
MySub()
or if it was a method of a particular class instance:
theClassInstance.MySub()
 
Hi John,

thanks for your reply, however that is not working. I may have not made myself clear..

I have a button on my form which is coded like this...

VB.NET:
 Private Sub MainFormNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainFormNew.Click
        Me.WorkshopJobsBindingSource.AddNew()
    End Sub

I have a ToolStripMenuItem which, when clicked I want to call the MainFormNew command.

How would I do this?

Thanks

John
 
While event handler methods are not any different from other methods, (you have to provide parameters to this method), you should not invoke event handler methods directly, they are used to handle events. It is not good practise to make a "false" call to such method because the code there should rely on that event actually happened.

You can make that button click by code MainFormNew.PerformClick() or put the code in its own method that both handlers can call. (like this http://www.vbdotnetforums.com/showpost.php?p=63980&postcount=2). If that's the only line of code you can also copy it to the other handler.
 
Back
Top