[RESOLVED] Can't unload controls created at design time!
In a WebBrowser project, I want a dynamic menu to pop-up when a Picture is clicked. The menu in the Menu Editor looks like this:
Back (mnuBack)
----BArrow(0) (mnuBArrow)
When the Picture is clicked, the menu shows a list of URLs the user had visited before the URL he is currently visiting. So if the user has visited the following sites (in the order specified)
& the user is currently viewing http://www.yahoo.com, then clicking the Picture would show the menu having the above 3 URLs. If any of the URLs is clicked in the menu, he should be taken to that site. Not only this, that URL in the menu should be deleted from the menu as well. This is what I have done to implement this:
VB Code:
Private Sub mnuBArrow_Click(Index As Integer)
Dim i As Integer
'imgCboURL(0) is the ImageCombo Address Bar
imgCboURL(0).Text = Me.mnuBArrow(Index).Tag
wWeb.Navigate2 mnuBArrow(Index).Tag
For i = 0 To Me.mnuBArrow.UBound
If (Me.mnuBArrow(i).Tag = Me.imgCboURL(0).Text) Then
Unload Me.mnuBArrow(i)
End If
Next
End Sub
What I find is if I click any URL in the menu apart from the 1st URL, then that URL gets deleted from the menu but if I click the 1st URL in the menu, then VB throws the Can't unload controls created at design time error.
First of all, why is VB generating this error & secondly, how do I resolve the issue?
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
This means that the first menu item has been created at design time. Controls that are created at design cannot be unloaded at runtime like the way we unload the controls that we create during runtime.
You will have to create the all the menuitems at run-time inorder to remove them at runtime.
Use [code] source code here[/code] tags when you post source code.
Now suppose I click the Picture; the menu unfolds. When I click www.google.com, VB generates the Can't load or unload this object error pointing to the bold line in the above code.
Note the MsgBox Me.mnuBArrow(i).Caption line. It correctly shows the Caption as www.hotmail.com but when I debug it, the next line throws the error!
In other words, irrespective of the URL I click in the menu, the last URL still remains in the menu. How do I get rid of the last URL?
Last edited by arpan_de; Mar 6th, 2006 at 10:58 AM.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Even though the message is different, aren't you still running into the same problem of not being able to unload the last member of a control array?
I don't think so since if I do Visible=False instead of unloading it, then I ge the error Visible property cannot be set for this member of the control array (or something of that sort) but using the Visible property for my first problem did resolve the issue which isn't the case now! What I don't understand is the MsgBox confirms that there is a last member of the control array; so why the error?
I don't understand why you use the loop in the first place. Wouldn't the following do the same thing?
As usual, Joacim, you are correct! Using a loop was indeed a stupid approach! Now let me try as you suggested.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Sorry Joacim but I think I have to use a loop since I want the URLs listed after the URL that has been clicked by the user in the menu to disappear from the menu! Correct me if I am wrong.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Oh, I must have misunderstood you then. Do you want the item that is clicked + all after to be deleted or just the items after? The following deletes every item after the one that is clicked.
Joacim, could you please help me with this problem?
I have 2 Pictures named Back & Forward. Clicking these 2 Pictures unfolds a menu which lists the URLs visited by a user. Of course, the URLs listed in the 2 menus depend on which URL the user is currently viewing. Suppose I visit the following URLs (in the order specified):
Assume that right now I am in page4. So when the Back Picture is clicked, the menu should list page1, page2 & page3 & the Forward Picture should be disabled since I am viewing the last page among the 4 pages.
Next I click page2 from the Back Picture menu. I am taken to page2. Now the Forward Picture menu should get enabled &, when clicked, should list page3 & page4 & the Back Picture menu should list only page1. Next I click page1 from the Back Picture menu. Under such circumstances, the Back Picture should be disabled since I am on the first page among the 4 pages & the Forward Picture menu should list page2, page3 & page4.
Next I click page3 from the Forward Picture menu. The Back Picture should get enabled & its menu should list page1 & page2 & the Forward Picture menu should list only page4.
In other words, I want the list of URLs to be juggled from one Picture menu to the other Picture menu depending on which page the user is currently viewing. Also the page that is being currently viewed should not be listed in either of the 2 Picture menus.
Please help me out with this.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
OK, I've written a class module for you that can handle this. It keeps the history and you can go back and forward in it as much as you wish. The class has 4 methods, 5 read-only properties, and it raises 2 different events.
The methods are:
Add(Url As String, Title As String)
Adds a new URL to the History list. This will clear the Forward list since you now navigate to a new location. This method will raise the HistoryChanged event.
Clear()
Clears the history, both the Back and Forward lists are emptied. This method will raise the HistoryChanged event.
GoBack([Steps As Long])
Goes back in the History list. You may optionally pass the number of steps it should go back, default is 1. An error will be raised if you try to go back more steps than possible. This method will raise the PositionChanged event.
GoForward([Steps As Long])
Goes forward in the History list. You may optionally pass the number of steps it should go forward, default is 1. An error will be raised if you try to go forward more steps than possible. This method will raise the PositionChanged event.
As you can see, the GoBack and GoForward methods may raise an error if you try to go Back/Forward when you can't do that. You can check the BackCount and ForwardCount properties (described below) to see how many steps you can go either back or forward.
The Properties are (all of them are Read-Only):
BackCount
The number of steps you can go back in the history list.
ForwardCount
The number of steps you can go forward in the history list.
BackText(Index, [HistoryText]) Index - Zero based index of the text you want to retrieve, so this is from 0 to BackCount-1. HistoryText - (Optional) Specifies if you want to retrieve the URL or the Title (defaults to URL), see notes below.
This property may raise a Subscript Out Of Range error if not the correct index is specified.
ForwardText(Index, [HistoryText]) Index - Zero based index of the text you want to retrieve, so this is from 0 to ForwardCount-1. HistoryText - (Optional) Specifies if you want to retrieve the URL or the Title (defaults to URL), see notes below.
This property may raise a Subscript Out Of Range error if not the correct index is specified.
CurrentText([HistoryText]) HistoryText - (Optional) Specifies if you want to retrieve the URL or the Title (defaults to URL), see notes below. Returns an empty string if no history is available.
Notes
The Back/Forward/CurrentText properties takes an optional argument called HistoryText, which specifies if you want it to return the URL or Title of the item. This argument is an enum with the possible values eUrl or eTitle, the default is eUrl.
The Events are:
HistoryChanged
This event is raised when you use either the Add or Clear methods. When this event is raised the Forward history is cleared and you should disable the picture box you use to show the Forward history. You should also check if the BackCount is greater then 0 to either disable or enable the picture box you use for the Back history.
PositionChanged
This event is raised when you go back or forward in the history. You should check both the BackCount and ForwardCount to enable/disable the appropriate picture boxes.
Usage: (Read carefully)
Even though you can rebuild the menus you use for the Back and Forward history in the HistoryChanged and PositionChanged events I wouldn't recommend it since it is better to create the menu just before you show them. You should however enable/disable the back and forward controls (picture boxes) in these events.
The following code will assume that you use the names mnuBArrow, mnuFArrow, picBArrow, picFArrow for the picture boxes and the menu arrays in your program.
The first thing you should do is of course to add the class to your project and then to declare an object in the General Declaration section of your Form. Since different web browser windows can have different history (don't confuse this with the other History treeview you have) the object should be private to each Form. The object should be created in Form_Load.
VB Code:
Private WithEvents oHist As CUrlHistory '<- Use WithEvents to sink the events
Private blnNoAdd As Boolean '<- [b]Described below[/b]
Private Sub Form_Load()
Set oHist = New CUrlHistory
'other code you may have in this event goes here
End Sub
You must create this object before you navigate anywhere since you probably want to add to the history in the NavigateComplete2 event. However since you don't want to add to the history when you navigate in it (when you use the Back or Forward arrows or menus) you should declare a flag that signals that the URL shouldn't be added. I called that blnNoAdd in the code above. So in the NavigateComplete2 event you would use code simular to this:
VB Code:
Private Sub wWeb_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
If blnNoAdd = False Then
oHist.Add URL, wWeb.LocationName
Else
blnNoAdd = False
End If
End Sub
OK, in the two events that is raised by the class you should enable or disable the picture boxes and in the PositionChanged event you can navigate the WebBrowser and set the blnNoAdd flag.
VB Code:
Private Sub oHist_HistoryChanged()
picFArrow.Enabled = False
picBArrow.Enabled = (oHist.BackCount > 0)
End Sub
Private Sub oHist_PositionChanged()
picFArrow.Enabled = (oHist.ForwardCount > 0)
picBArrow.Enabled = (oHist.BackCount > 0)
blnNoAdd = True
wWeb.Navigate2 oHist.CurrentText '<- CurrentText returns the URL by default
End Sub
Now you may create the popup menus when the user click on these picture boxes. Since they are disabled if there is no current history you don't have to care about empty menus since the Click event isn't raised for a disabled control. This code will also assume that for the Back menu you want it to be displayed in the same order as IE does, the latest visited URL is shown first.
VB Code:
Private Sub picBArrow_Click()
Dim n As Long, nCount As Long
'First clear the menu
Do While mnuBArrow.UBound > 0
Unload mnuBArrow(mnuBArrow.UBound)
Loop
'Now recreate the menu
nCount = oHist.BackCount - 1
For n = 0 To nCount
If n > 0 Then
Load mnuBArrow(n)
End If
mnuBArrow(n).Caption = oHist.BackText(n, eTitle)
mnuBArrow(n).Visible = True
'You do not have to store the URL in the Tag of the menu
Now all you have to do is to navigate back or forward when the menu items are clicked. Since the menu items have an Index that goes from 0 and up and you want to go either back or forward that many steps + 1 the code will be very simple. We don't actually have to navigate the webbrowser here since that is done in the PositionChanged event.
VB Code:
Private Sub mnuBArrow_Click(Index As Integer)
Call oHist.GoBack(Index + 1)
End Sub
Private Sub mnuFArrow_Click(Index As Integer)
Call oHist.GoForward(Index + 1)
End Sub
Even though it may look like this class has different arrays for the Back and Forward lists it doesn't. Internally the class only have one string array containing the URL and the Title (separated by a NULL character) of the whole history. It then has a private Long variable called nCurrentPos that points to the current location, all the items before this position is the Back history and everything after it is the Forward history. When you use the Add method everything after the current position is cleared from the array so the Forward history is then cleared. You can look at the code to see how all of this is implemented even though it isn't necassary for you to understand the code to be able to use the class, but the code isn't very complex and I have added (I hope ) enough comments to make it self documented, but if you have any questions just ask.
Joacim, your code does work great but for a small problem. Assume that the home page has been set to about:blank. I load the browser. The browser opens with the about:blank page. Next I navigate to www.google.com. Now when the I click the arrow Picture accompanying the Back button, about:blank gets listed in the menu. Now I don't want about:blank to get listed under such circumstances. In fact, I don't want about:blank to be listed at all in either of the 2 menus. How do I ensure that?
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Well, you can of course decide to make an ignore list. It's up to you how you want to implement that. If there is a very small list, or maybe only about:blank you can of course put it into the NavigateComplete2 event since that is where you add the URLs to the object.
VB Code:
Private Sub wWeb_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
If blnNoAdd = False Then
[b] Select Case LCase$(URL)
Case "about:blank"
'do nothing
Case Else [/b]
'add it to our history list
oHist.Add URL, wWeb.LocationName
[b] End Select [/b]
Else
blnNoAdd = False
End If
End Sub
If there is a larger list of URLs you want to ignore you can build it into the class and do the compare the URL passed to the Add method against this list. If the URL already exists then simply exit from the method without adding the URL.
Joacim, that does ensure that about:blank doesn't get added to the menu but when the browser loads & the back arrow Picture is clicked, still a menu comes up without any items (a blank menu). How do I get rid of the blank menu?
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Joacim, another problem - the back arrow Picture is accompanied with a Back button & similarly, the forward arrow Picture is accompanied with a Forward button (like IE). These 2 buttons (actually they are PictureBoxes named picBack & picForward) also have to be enabled/disabled as & when the 2 arrow Pictures get enabled/disabled. To accomplish this, I added a few lines in the oHist_HistoryChanged sub-routine & the oHist_PositionChanged sub-routine (the lines which are bold are the lines I added).
wWeb.Navigate2 oHist.CurrentText '<- CurrentText returns the URL by default
End Sub
But the Back & Forward Pictures don't get enabled/disabled in sync with the 2 arrow Pictures. Moreover, the picBack_Click event function invokes the mnuBackArrow_Click(0) event function & the picForward_Click event function invokes the mnuForwardArrow_Click(0) event function.
Could that be the reason why the Back & Forward Pictures are getting enabled/disabled in sync with the 2 arrow buttons? Please tell me where am I erring.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Both of those picture boxes should also be disabled from start, set the Enabled property to False during design time. Also, calling the click event of the menus just means an extra call, just this code instead:
VB Code:
Private Sub picBack_Click()
oHist.GoBack
End Sub
Private Sub picForward_Click()
oHist.GoForward
End Sub
As you can see I don't pass any arguments to the call of GoBack and GoForward above since the default value is to go back/forward 1 step.
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
In that case I don't understand it... Do you Enable any of those in any of the events of the WebBrowser? If you use the code you showed above then the Enabled property of picBack will have the same value as the Enabled property of picBackArrow. So the only conclusion I can come up with is that you must change the Enabled property somewhere else as well.
You are absolutely right, Joacim. I was enabling those 2 Pictures in the WebBrowser's CommandStateChange event function.
Joacim, I really don't know how to express my gratitude to you for all the help (& that too not for the first time) you have extended towards me. Even a trillion Thanks aren't enough. Seldom does one help a needy person without expecting anything in return in today's world & that is exactly what you have done unselfishly to a person (i.e. me ) who doesn't know anything about you except for your name & nationality. I really appreciate your efforts & the time you have invested not only in resolving my problems but also for enriching my VB know-how from the bottom of my heart.
Now back to some serious business - Joacim, you have used a Class Module to accomplish this task. Couldn't the same been done without using a Class Module? Of course, it definitely could have been since in programming, one thing can be done in more than 1 way; so what made you use a Class Module here & not a BAS Module?
To be very honest, I haven't ever used a Class Module since I started doing VB about 3-4 months back.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Yes you could have accomplished the same thing in an other way. But I like object oriented programming, even if VB6 doesn't fully support OOP it does have many of those ideas implemented. VB has also always been event driven and a BAS module can't raise events while a class module can. Just look at how you implemented the use of the object you create from this class in your Form. You build up the rest of the GUI for this back/forward feature from the events raised by this class. In your Form you don't need much code at all to make it work.
Why do you use components in VB? Because they are easy to use and highly reusable, and once you've learned it, it's nice to write event written code. Something happened over there and it signals it back to me over here via an event. In this event I can now decide what I should do with the information I got from over there. This is IMHO a very clean way of writing and using your code. You don't even have to see the source of the class to be able to use it once you know how to use it, that is once you know the properties, methods and events the class expose to you.
How often do you think about how the source code for the different classes in the FSO looks like? Probably not much, even if it might be nice to have source code to learn from the main goal is always to get your application to work the way you and your users want it too.
I always wrap most of my code into classes, and use BAS modules for things like subclassing and callback procedures since they unfortunatly can't be inside a class module. I also always treat my Forms as the class modules they basically are. I never for example use Form2.Show when I can use the much longer code:
VB Code:
Dim newForm As Form2
Set newForm = New Form2
newForm.Show
The above example use a Dim statement however that is often declared as Private or Public somewhere else in the code. Why do I use this approach when I could simply use the name I gave my Form during design time you might ask? Well, first of all the name I give my Form during design time is the class name and not the object name. VB however automatically creates a Form object with the same name. This is however not a strongly bound object, in fact it is the same as if you yourself would have put the following in a BAS module.
VB Code:
Public Form1 As New Form1
Public Form2 As New Form2
'and so on for each of the Form you have in your project
You might have encountered several threads in this and other forums that strongly advice against using the New keyword on the same line as the declaration. This is because the object isn't created because of this declaration, instead it is created when you first use it. So as soon as you set a property value of the Form or of one control on that Form to a new value, or call one of the methods (like Form2.Show for example) the object (the Form in this case) is created. However because of this each time you change a property or call one of the methods of this object, VB has to first check if it needs to create the object or if the object already exists. That is why it's called loose binding, the object is created when it is used.
However constantly checking if the object is created or not takes time and the code runs slower. Also, even if you unload the Form and set the Form object to Nothing, and then for some reason access one of the properties the Forn is recreated and reloaded into memory (but unless you call the Show method it isn't visible). Just do a forum search for something like "I've unloaded my Form but the program is still running and I can see it in the Task Manager... Why is that?" and you'll get a bunch of threads (well maybe not if you use that exact search phrase, but you'll understand what I mean, I hope) all coming up with the solution to loop through the Forms collection and unloading each Form and to set it to Nothing. Well, if you always use strong bindings with your Forms you would never have that problem.
Joacim, just now I discovered a weird problem with your code. I loaded the browser; the back & its arrow Pictures were disabled. Next I navigated to www.rediff.com. Strangely both the Pictures got enabled. Not only this, when I clicked the back arrow Picture, the menu listed the title of the web page 5 times!
After a few experiments, when I had a look at the source of the web page, I found that there were 5 <IFRAME></IFRAME> tags & that's the reason why the menu showed 5 items.
I confirmed this by closing the browser, re-loading it & navigating to www.yahoo.com. In this case also, the Back & its arrow Picture were enabled & Yahoo was listed once in the menu though the 2 Pictures should have been disabled. When I had a look at the source of the page, I found that there is one <IFRAME></IFRAME> tag which is why Yahoo was listed once in the back arrow Picture menu.
There's another issue. I have given users the option to block pop-ups. Now www.rediff.com opens a pop-up & the back arrow Picture menu even listed the URL of that pop-up though I had blocked the pop-up! Irrespective of whether users block or allow pop-ups, pop-ups shouldn't be listed in either of the 2 arrow Picture menus since pop-ups always open in a new browser window, isn't it?
These 2 are grave problems. How do I overcome them?
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Well, it's not the code in the class that is wrong. The URLs are however added in the NavigateComplete2 event, and apparantly that is called for each IFrame that is loaded, you have to find a workaround for that.
About the popup killer... how are you handling that? Remember that you'll add new URL's to this history only in the NavigateComplete2 event, maybe there are some other WebBrowser event you should use? Sorry for not providing any more help, but the computer I'm currently at doesn't have VB6 and I don't use the WebBrowser object often enough to remember the event names it has .
No, no, Joacim I am not saying that the code in the Class Module is wrong; it's very much correct. Can you suggest a workaround?
One workaround which I tried is adding the URL in the BeforeNavigate2 event function & unloading those menu items which are about:blank in the picBArrow_Click event function. This correctly lists the URLs in the menus but the navigation isn't correct.
For e.g. I first visit www.yahoo.com & then www.rediff.com. When I am in rediff.com, the back arrow menu lists Yahoo but when I click Yahoo to go back to www.yahoo.com, the browser doesn't navigate to Yahoo; it stays put in www.rediff.com. Any workaround to this?
Joacim, please don't leave me in the middle of the sea. It's an earnest request. Of course, in the meantime, I will be trying for a workaround & if I do get one, I will definitely intimate you.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
You can't just remove items from the menu since it's the class that controls the navigation, even if you don't show an URL the class will make you navigate to it. I'm not leaving you, I just don't currently have access to a computer with VB so I can't do any testing.
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Sorry for the late reply but I haven't had time to look at this until now. I found that instead of using the NavigateComplete2 event to add to the history I used the DownloadComplete event like this (my webbrowser control is simply called web):
VB Code:
Private Sub web_DownloadComplete()
If oHist.CurrentText <> web.LocationURL Then
oHist.Add web.LocationURL, web.LocationURL
End If
End Sub
Of course you should now first check your ignore list for URLs that shouldn't be added to the history, but you must remember that the Back and Forward doesn't work properly if you do. Say that you first navigate to VBForums.com and from there to microsoft.com. The VBForums.com should now be in your Back history. Now say you navigate to about:blank and you ignore to add that to the history then you can't navigate back to microsoft.com since the oHist object still thinks that microsoft.com is the current location.
Thanks Joacim, your suggestion is now working perfectly. In fact, I added that code snippet in post #28 in the NavigateComplete2 event function instead of in the DocumentComplete event function (as you had suggested) & it works just as fine.
Say that you first navigate to VBForums.com and from there to microsoft.com. The VBForums.com should now be in your Back history. Now say you navigate to about:blank and you ignore to add that to the history then you can't navigate back to microsoft.com since the oHist object still thinks that microsoft.com is the current location.
Yeah, you are right on that point but that's OK........no problems . Let me see if I can do something about it.
Whooosh!! Got rid of a big headache finally.......all thanks to you
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?