Unexpected error?

Posts 115 of 16 · Page 1 of 2
Unexpected error?
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
Quote Originally Posted by willrulz188 View Post
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.
Quote Originally Posted by SofaKingH4rd View Post
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)
Quote Originally Posted by freedompeace View Post
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 :|
Quote Originally Posted by Hassan View Post


/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.
Quote Originally Posted by freedompeace View Post


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]
Quote Originally Posted by *****179 View Post
close right there...second line..
[highlight=vb.net]
e As System.EventArgs)
[/highlight]
How do you do a vb.net code?
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)
Hurr durr.
@SofaKingH4rd

[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]

Oh shit ***** already posted it my bad.
Posts 115 of 16 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?