|
-
Jan 5th, 2003, 02:23 AM
#1
Thread Starter
Addicted Member
Why cant I Call a sub??
Look at the following code. When I try to call a click event from within a menu event, it won't let me. What am I doing wrong?
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog()
OpenFileDialog1.Filter = "All files (*.*)|*.*"
If openFileDialog1.ShowDialog() = DialogResult.OK Then
MsgBox("worked!")
End If
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Call Button1_Click()
End Sub
-- Ethan --
VB6, VB.NET, C#, SQL, XML, ADO.NET, ASP.NET, HTML.
MCP & A+ Certified. Looking for a job in the Seattle, WA area.
-
Jan 5th, 2003, 02:34 AM
#2
Sleep mode
the code answered your question :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
the important part in this line is "Handles Button1.Click" so obviously , the sub is attached to (the control and control event) .
no control can use its code (not quite sure but it seems like so.)
-
Jan 5th, 2003, 02:35 AM
#3
You didn't pass anything into the required parameters.
Button_Click(Me,Nothing)
-
Jan 5th, 2003, 02:36 AM
#4
You could also just add the menuitem to the handles:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, MenuItem2.Click
-
Jan 5th, 2003, 02:40 AM
#5
Sleep mode
sorry I was fooled by the keyword Handles .Next time I wouldn't trust these meaningless words.
Edneeis is definitely right ,I tried that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|