locked
I have a question RRS feed

  • Question

  • I started a new project and view the code of Form1. When I type the folowing code:

     

    Code Snippet

    Sub Hello()

     

    MsgBox ("Hello world!")

     

    End Sub

     

    Between the Public class tags, and I start Debugging, I get not a box with Hello world! how can I do this?

    That I get another box with the text, and not in Form1?

     

    Sunday, July 1, 2007 6:59 PM

Answers

  • You are just defining the method, you are not calling it. If you want to get the messageon a button click, then add a button to the form, doubleclick it, then you got the handler of the click event, write in that handler: Hello(), this will let you see the box !

    hope this helped.
    Sunday, July 1, 2007 8:30 PM
  • If you want the message box to pop up as soon as you run the program, then place your code inside the FormLoad event.  Double-click the empty form and place your code inside the header and the End Sub, but without the Sub Hello header.  It should look something like this:

     

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    MsgBox("Hello, World!")

    End Sub

    End Class

     

    Otherwise, place a button on your form and double-click the button to open the code window.  Then place your code like this:

     

     

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    MsgBox("Hello, World!")

    End Sub

    End Class

     

     

    If you insist on using your subprocedure, then you will have to call it, either from the FormLoad event, or the Button Click event, or both:

     

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Call Hello()

    End Sub

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Call Hello()

    End Sub

     

    Sub Hello()

    MsgBox("Hello, World!")

    End Sub

    End Class

     

     

    Sunday, July 1, 2007 10:01 PM

All replies

  • You are just defining the method, you are not calling it. If you want to get the messageon a button click, then add a button to the form, doubleclick it, then you got the handler of the click event, write in that handler: Hello(), this will let you see the box !

    hope this helped.
    Sunday, July 1, 2007 8:30 PM
  • If you want the message box to pop up as soon as you run the program, then place your code inside the FormLoad event.  Double-click the empty form and place your code inside the header and the End Sub, but without the Sub Hello header.  It should look something like this:

     

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    MsgBox("Hello, World!")

    End Sub

    End Class

     

    Otherwise, place a button on your form and double-click the button to open the code window.  Then place your code like this:

     

     

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    MsgBox("Hello, World!")

    End Sub

    End Class

     

     

    If you insist on using your subprocedure, then you will have to call it, either from the FormLoad event, or the Button Click event, or both:

     

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Call Hello()

    End Sub

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Call Hello()

    End Sub

     

    Sub Hello()

    MsgBox("Hello, World!")

    End Sub

    End Class

     

     

    Sunday, July 1, 2007 10:01 PM