We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,374 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Beginning with VB.NET

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!

4
Contributors
5
Replies
2 Hours
Discussion Span
10 Months Ago
Last Updated
6
Views
Question
Answered
me_coolvibes
Newbie Poster
8 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

there is no error in this code but it suold be inside the class

HibaPro
Junior Poster
126 posts since Jun 2012
Reputation Points: -3
Solved Threads: 2
Skill Endorsements: 0

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

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9

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.

Luc001
Posting Pro in Training
413 posts since Mar 2010
Reputation Points: 93
Solved Threads: 107
Skill Endorsements: 1

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

me_coolvibes
Newbie Poster
8 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Thanks everyone, it just worked!

me_coolvibes
Newbie Poster
8 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 10 Months Ago by Luc001, HibaPro and hericles

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0689 seconds using 2.64MB