Ryan Ryan - 5 months ago 16
Vb.net Question

Microsoft Visual Basic 2008 Express Edition End of Statement Expected

I have tried testing my web browser I have made by following a YouTube video. It doesn't work though. What is wrong with it?

Here is my code

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("www.google.com")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.GoBack()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoForward()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Navigate("http://www.google.com/search?g=") & (TextBox2.Text)
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Stop()
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
WebBrowser1.Refresh()
End Sub

End Class

Answer

You don't say where the error occurred, which makes it very hard to help you. But it looks like your problem is in this line:

WebBrowser1.Navigate("http://www.google.com/search?g=") & (TextBox2.Text)

This should be

WebBrowser1.Navigate("http://www.google.com/search?g=" & TextBox2.Text)

As it is, you have an expression on a line by itself; the concatenation makes no sense.


In the future, please be sure to include a Minimal, Complete, and Verifiable example. Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers.

Comments