I have jsut started using visual basic and I have came across a error.
The code looks all right to me...Please could someone tell me what I need to change for it to debug successfully please?
screenshot -
code -
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer
number1 = 3
number2 = 5
answer = number1 + number2
MsgBox(answer)
End Sub
Should just be
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer
number1 = 3
number2 = 5
answer = number1 + number2
MsgBox(answer)
End Sub
Originally Posted by willrulz188
Should just be
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer
number1 = 3
number2 = 5
answer = number1 + number2
MsgBox(answer)
End Sub
I just done that and i still get this error.
Error 1 Statement is not valid in a namespace.
Originally Posted by SofaKingH4rd
I just done that and i still get this error.
Error 1 Statement is not valid in a namespace.
You need to enclose your code in a class. Namespaces are just a way to organize your classes.
Here's the solution [Wrapped your code around a class and a namespace]:
[highlight=vbnet]Namespace WindowsApplication3
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer
number1 = 3
number2 = 5
answer = number1 + number2
MsgBox(answer)
End Sub
End Class
End Namespace[/highlight]
@willrulz188: How come you changed the sub to handle Button3 instead of Button1 ? ;D
You forgot the closing parenthesis.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click)
Originally Posted by freedompeace
You forgot the closing parenthesis.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click)
/FP.
Where's the opening brace for the one you closed ? There's no need for that bracket. It's VB :|
Originally Posted by Hassan
/FP.
Where's the opening brace for the one you closed ? There's no need for that bracket. It's VB :|
Sub Button_Click(
isn't exactly functional. You still need to close any brackets you open. Or ... if you're right, what the fuck ._.
I'm going to QQ right here right now.
In any case, you should have it to keep my sanity.
Originally Posted by freedompeace
Sub Button_Click(
isn't exactly functional. You still need to close any brackets you open. Or ... if you're right, what the fuck ._.
I'm going to QQ right here right now.
In any case, you should have it to keep my sanity.
close right there...second line..
[highlight=vb.net]
e As System.EventArgs)
[/highlight]
Originally Posted by *****179
close right there...second line..
[highlight=vb.net]
e As System.EventArgs)
[/highlight]
simplified...
[highlight=vb.net]
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number1 As Integer
Dim number2 As Integer
number1 = 3
number2 = 5
MsgBox(number1 + number2)
End Sub
End Class
[/highlight]
I'm going to leave this for a while.
Thank you all for your help.
you do a highlight=vb.net in [], and close it with /highlight in []
[highlight=vb.net]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox5.Text = ("") Then
MsgBox("Please, put a valid number value", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ERROR")
Else
End If
Timer1.Interval = TextBox1.Text * 1000
End Sub[/highlight]
It worked fine for me when I debugged it.
Atleast this part works :
Code:
Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer
number1 = 3
number2 = 5
answer = number1 + number2
MsgBox(answer)
[highlight=vb.net]Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer
number1 = 3
number2 = 5
answer = number1 + number2
MsgBox(answer)
End Sub
End Class[/highlight]