In a Web Browser project, whichever web page a user has navigated to, I am adding the titles of the web pages along with their respective URLs in a text file. I am then populating 2 Collections - one with the title of the web page & the other one with the URL of the web page. This is how I am doing it:There is another function (not shown) which loads a menu with these web pages. The web page the user currently is in is checked in the menu. A user can navigate in 2 ways - either by clicking a link or by pressing the Back/Forward buttons. If the Back or Forward button is pressed then a Public Boolean blnNavButtons is set to True & in the BeforeNavigate2 event function:VB Code:
Private Sub wWeb_TitleChange(ByVal Text As String) Dim iFile As Integer Dim FileName As String Dim colTitle As Collection Dim colURL As Collection Set colTitle = New Collection Set colURL = New Collection iFile = FreeFile FileName = App.Path & "\SessionHistory.txt" Open FileName For Input As #iFile Do While Not EOF(iFile) Input #iFile, strTitle, strURL colTitle.Add strTitle, strTitle colURL.Add strURL, strURL Loop Close #iFile End SubAssume that a user goes to Page1, clicks a link & goes to Page2. In Page2, he again clicks a link which takes him to Page3 & finally in Page3, he clicks a link which takes him to Page4. Note that while he is navigating, the menu is simultaneously getting loaded with Page1, Page2, Page3 & Page4 which is now checked.VB Code:
Private Sub wWeb_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean) If (blnNavButtons = True) Then blnLinkClick = False Else blnLinkClick = True End If End Sub
Right now, the user is in Page4. Now assume that he clicks the Back button & goes to Page3. Again he clicks the Back button & goes to Page2. Again he clicks the Back button which takes him to Page1. Now if the user clicks a link in Page1 which takes the user to Page5, I want Page2, Page3 & Page4 to get deleted from the Collections as well as from the menu. This is how I have done it (continuing wWeb_TitleChange where it has been left):The above code works fine but a problem creeps under the following circumstance:VB Code:
Private Sub wWeb_TitleChange(ByVal Text As String) .......... .......... .......... Close #iFile For i = 1 To colURL.Count If (colURL.Item(i) = wWeb.LocationURL) Then If (colURL.Count > i) Then If (blnLinkClick = True) Then For j = i + 1 To colURL.Count colURL.Remove j colTitle.Remove j Unload mnuSessionHistory(j - 1) Next j FileName = App.Path & "\SessionHistory.txt" Open FileName For Output As #iFile For j = 0 To mnuSessionHistory.UBound Write #iFile, mnuSessionHistory(j).Caption, mnuSessionHistory(j).Tag Next Close #iFile End If End If End If Next i End Sub
User goes to Page1, clicks a link & goes to Page2, clicks a link & goes to Page3, clicks a link & goes to Page4. The menu now looks like this:
Page4 is checked. Now in Page 4, there is a link which takes the user back to Page1. So when this link is clicked, all the menu items get deleted & only Page1 remains in the menu where as I want the menu to look like this:Code:Page1
Page2
Page3
Page4
With Page1 checked.Code:Page1
Page2
Page3
Page4
Page1
What modifications are needed in the above code to do this?
