Results 1 to 5 of 5

Thread: Why cant I Call a sub??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    Seattle, WA USA
    Posts
    216

    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim openFileDialog1 As New OpenFileDialog()
    3.  
    4.         OpenFileDialog1.Filter = "All files (*.*)|*.*"
    5.         If openFileDialog1.ShowDialog() = DialogResult.OK Then
    6.             MsgBox("worked!")
    7.         End If
    8.     End Sub
    9.  
    10.     Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
    11.         Call Button1_Click()
    12.     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.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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.)

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You didn't pass anything into the required parameters.

    Button_Click(Me,Nothing)

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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
  •  



Click Here to Expand Forum to Full Width