Results 1 to 6 of 6

Thread: Beginning Microsoft VB 2010

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Question Beginning Microsoft VB 2010

    Hello everyone.
    Im now reading the VB 2010 beginner book by Thearon Wills and Bryan Newsome. im 13 years old and im currently stuck. i tried to code the variable program yesterday but something went wrong. is it because i use Visual Studio 2010 Express? every code is exactly the same like in the book. This is at Page 40. help please!

    Code:
    Public Class Form1
    
        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
            Dim intNumber As Integer
            intNumber = 27
            intNumber = intNumber + 1
            MessageBox.Show("Value of intNumber + 1 = " & intNumber.ToString, _ "Variables")
    
        End Sub
    End Class
    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Beginning Microsoft VB 2010

    Welcome to VBForums

    Thread moved from 'Office Development' forum to 'VB.Net' (VB2002 and later) forum.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: Beginning Microsoft VB 2010

    Thanks

    im so sorry for posting in wrong section too ^^

  4. #4
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: Beginning Microsoft VB 2010

    Not sure, but I believe your messagebox line got a syntax error:
    Code:
    MessageBox.Show("Value of intNumber + 1 = " & intNumber.ToString, _ "Variables")
    To:
    Code:
    MessageBox.Show("Value of intNumber + 1 = " & intNumber.ToString, "Variables")
    The '_'-sign is used to make code flow over to the next line, like this:
    Code:
    Dim mystring As String = "This string is extremely long so I " & _
    "use a '_' character to make it flow over correctly"
    Or use the good ol' MsgBox:
    Code:
    MsgBox("Text to display")
    Other than that there are no errors to be seen.

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Beginning Microsoft VB 2010

    *Ahh, beaten!*

    Could you describe what you mean by "something went wrong"?

    The only odd part I see is here:
    Code:
    MessageBox.Show("Value of intNumber + 1 = " & intNumber.ToString, _ "Variables")
    See that "_" character? That's called the "line continuation operator". Since VB .NET doesn't use a character like ";" to mean "end of line", the syntax doesn't provide an immediate way for you to separate an expression over multiple lines of code. If you end a line with "_", that's a hint to the compiler that you have split an expression:
    Code:
    MessageBox.Show("Value of intNumber + 1 = " & intNumber.ToString(), _
                    "Variables")
    In VB 2010, you don't *always* have to use the line continuation operator when splitting an expression, but there are still scenarios where it's needed.

    Anyway, my guess is if you put the "_" on a line, you are not allowed to place any more code on that line. Either start a new line after it or delete the "_" from your code.

    If that's not the problem, please include a detailed explanation of what you expect to happen and what's actually happening; make sure to include this in all posts.

  6. #6
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: Beginning Microsoft VB 2010

    *Ahh, beaten!*
    Haha, happened to be a few times too.

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