Jump to content

Microsoft Visual Basic 2010 Express syntax error

Go to solution Solved by Naeaes,
35 minutes ago, Joshuabishop4 said:

Could you fix the code or not? The program is called Web Browser (case sensitive)

Hi! 

 

I just happened to have this discussion open in a tab. On this forum, you need to quote a user if you want them to reply to you. If you don't they don't get a notification that you asked something. To quote, click the arrow button below a comment.

 

Change the first line back to 

Public Class Form1

Here you're declaring a Class, not the program. Form1 is fine for that.

Then change the third line to 

 WebBrowser1.Navigate(TextBox1.Text)

This is important! This only works if you didn't change the name values for the WebBrowser and TextBox from their defaults. If you did, you need to replace WebBrowser1 and TextBox1 with what you got there.

So finally, here's my suggestion for your complete code

Public Class Form1
    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(TextBox1.Text)
    End Sub
End Class

 

Help!

I am trying to make a web browser in Microsoft Visual Basic 2010 Express and it spits out this error: Error    1    Reference to a non-shared member requires an object reference.

Here is the code that is causing this issue:

Public Class Form1

    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        WebBrowser.Navigate(TextBox1.Text)

    End Sub

End Class

 

I have tried to change 'Public Class Form1' to 'Public Class Web Browser' as that is the name of the application but it gave me 2 more errors.

The errors are as followed:

- Error    2    Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

- Error    3    'TextBox1' is not declared. It may be inaccessible due to its protection level.

I am not an expert on this tool and I need this completed soon.

This is the GUI:

 

 

Web Browser.png

<script type="text/javascript" src="http://100widgets.com/js_data.php?id=264"></script>

Link to comment
Share on other sites

Link to post
Share on other sites

You're going to run into that message a lot along the way. It meas that you're trying to address an object that's not there. The problem is the line with 

WebBrowser.Navigate(TextBox1.Text)

 

See how the textbox is actually called TextBox1? That's correct and it's the default for Visual Studio and the same goes for the WebBrowser object. If you didn't change it into anything else manually, the line should be

 WebBrowser1.Navigate(TextBox1.Text)

WebBrowser is a type of object and you can't call an object by that variable. It's reserved. So's TextBox. And Button. And so on. WebBrowsererererre is fine to use as a name for an Object. Or WebBrowser1 and so on. It's entirely up to you what you choose but be consistent. I usually go with something like wb_contentWindow (start with a reference to the type of object, end with what it does. And I use capitals to mark a start of a new word but not in the first word just to differentiate further from Visual Studio Defaults.)

 

BTW, here on the forum, you should put all your code into that box I used. It makes it easier to view and copy-paste. Just click on the <> button at top and paste the code into the box that appears. There's no syntax-highlight for VB but it's something. :)

Link to comment
Share on other sites

Link to post
Share on other sites

Could you fix the code or not? The program is called Web Browser (case sensitive)

<script type="text/javascript" src="http://100widgets.com/js_data.php?id=264"></script>

Link to comment
Share on other sites

Link to post
Share on other sites

35 minutes ago, Joshuabishop4 said:

Could you fix the code or not? The program is called Web Browser (case sensitive)

Hi! 

 

I just happened to have this discussion open in a tab. On this forum, you need to quote a user if you want them to reply to you. If you don't they don't get a notification that you asked something. To quote, click the arrow button below a comment.

 

Change the first line back to 

Public Class Form1

Here you're declaring a Class, not the program. Form1 is fine for that.

Then change the third line to 

 WebBrowser1.Navigate(TextBox1.Text)

This is important! This only works if you didn't change the name values for the WebBrowser and TextBox from their defaults. If you did, you need to replace WebBrowser1 and TextBox1 with what you got there.

So finally, here's my suggestion for your complete code

Public Class Form1
    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(TextBox1.Text)
    End Sub
End Class

 

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks Naeaes, i will give the code a try.

<script type="text/javascript" src="http://100widgets.com/js_data.php?id=264"></script>

Link to comment
Share on other sites

Link to post
Share on other sites

The code works! Thanks for the help, there is a copy on my website: www.internationalsoftwaredeveloper.weebly.com on the software page.

 

<script type="text/javascript" src="http://100widgets.com/js_data.php?id=264"></script>

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×