Hi,

I have just started learning VB.NET and recently tried to write my first piece of code.
I am getting an error message that says: ******Statement cannot appear within a method body.End of method assumed.
******
Here's my piece of code:

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

    Dim name1, name2 As String

    name1 = "Walter Bishop"
    name2 = "Olivia Dunham"

    MsgBox("The main characters of FRINGE are " & name1 & "and" & name2)


End Sub

Could someone please help me understand why this is happening? Thanks!

You are missing some syntax somewhere in the class, most likely a method that has no End Sub.

Hi,

Your Class should look like this:

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim name1, name2 As String
        name1 = "Walter Bishop"
        name2 = "Olivia Dunham"
        MsgBox("The main characters of FRINGE are " & " " & name1 & " " & "and" & " " & name2)
    End Sub
End Class

BTW your code is working perfect.
I only changed the message a little to make it more readable.

Comments
I did write it all within the class...complete with End Class....just gave out the main code here...didn't work!

I did write it all within the class...complete with End Class....just gave out the main code here...didn't work!

This question has already been answered. Start a new discussion instead.