[VB2005] Webbrowser back button.

Custom Title Activated
Loyal Member
Joined
Apr 12, 2004
Messages
1,101
Reaction score
0
I am trying to create a back button for a web browser.. I know there are controls I could use instead of doing it this way, but right now I'm just trying to learn how to do things my own way.

webbrowser2 = Upon loading a new page, sets the value backlink.text to the value of "number" then sets the value of "number" to the URL of the current page, updating the value of "number"
button2 = the back button, makes webbrowser2 navigate to the URL which is stored as backlink.text
number = a variable which is set to the url of webbrowser2
backlink = is set equal to the value of "number"

Also, I was trying to make the address in the text field update itself the the url of the current page every time a new page was loaded (see webbrowser2 section).

For some reason, this code doesn't want to work (it compiles fine, just doesn't work the way I want it to). That's where I need some advice. can someone shed some light as to why this isn't working?

Source:
Code:
Public Class Form1

    Dim number

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        lasttyped.Text = address.Text
        WebBrowser2.Navigate(address.Text)
    End Sub

    Private Sub WebBrowser2_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser2.DocumentCompleted
        backlink.Text = number
        number = WebBrowser2.Url
        address.Text = number

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        WebBrowser2.Navigate(backlink.Text)
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

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

End Class

Also note, this is my first project with VB.
 
Each time u call a private sub, VB forgets the variables unless u parse it to memory.

right here u are declairing some variables
backlink.Text = number
number = WebBrowser2.Url
address.Text = number

But VB forgets that info once the private sub ends.

What u need to do is create sub procedures inside your private class, or have your click event (private sub button2_click) call upon another Function rather than create 6 seperate procedures.
 
Each time u call a private sub, VB forgets the variables unless u parse it to memory.

right here u are declairing some variables


But VB forgets that info once the private sub ends.

What u need to do is create sub procedures inside your private class, or have your click event (private sub button2_click) call upon another Function rather than create 6 seperate procedures.

Actually he's not declaring variables, he's assigning variables. And he has already created 6 prodecures.
 
I appologize for misuse of termanology, but regardless... once you type "End Sub" unless you have parsed it to memory, what you have declaired will be reset to zero.

And to Chojiro, look at what i stated... i said Do Not create 6 procedures, try to minimize it as much as possible so that the program will be more efficient. If need be, create multiple functions to perform the tasks seperately.
 
Last edited:
Back