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 :)
Re: Beginning Microsoft VB 2010
Welcome to VBForums :wave:
Thread moved from 'Office Development' forum to 'VB.Net' (VB2002 and later) forum.
Re: Beginning Microsoft VB 2010
Thanks :)
im so sorry for posting in wrong section too ^^
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.
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.
Re: Beginning Microsoft VB 2010
Haha, happened to be a few times too. :bigyello: