I am creating a webbrowser and when the user enter a webpage into the address bar (combo box) it adds it to it for later reference.
I want it so that it does not add it again, if it is already there. How do i do this? thanks in advanced
Printable View
I am creating a webbrowser and when the user enter a webpage into the address bar (combo box) it adds it to it for later reference.
I want it so that it does not add it again, if it is already there. How do i do this? thanks in advanced
See my post#4 in this thread.
I have this and it is not working:
VB Code:
Private Sub brwWebBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant) Dim i As Integer Dim bFound As Boolean Me.Caption = brwWebBrowser.LocationName & " - RapidFriends Explorer" If cmbAddress <> cmbAddress.Text Then For i = 0 To cmbAddress.ListCount - 1 If cmbAddress.List(i) = brwWebBrowser.LocationURL Then bFound = True Exit For End If Next i End If mbDontNavigateNow = True If bFound Then cmbAddress.RemoveItem i End If Dim strSomeValue lngRetVal = SendMessageString(cmbAddress.hWnd, CB_FINDSTRINGEXACT, -1&, strSomeValue) If lngRetVal > -1& Then ' Do nothing Else cmbAddress.AddItem brwWebBrowser.LocationURL, 0 cmbAddress.ListIndex = 0 End If stbBrowser.Panels(1).Text = "Done!" mbDontNavigateNow = False End Sub
strSomeValue should be replaced by the string or value you are looking for.
I'm not convinced about the purpose of having loop and SendMessage all together - one or the other I guess... :confused:
i was just using Martin's code
I think what Rhino was trying to ask is what purpose does this code serve?
VB Code:
If cmbAddress <> cmbAddress.Text Then For i = 0 To cmbAddress.ListCount - 1 If cmbAddress.List(i) = brwWebBrowser.LocationURL Then bFound = True Exit For End If Next i End If
I am confused. What do i need to put in the code, so that it will not add the url to the combobox, if it is already there?
There is no need for that loop. Using Martin's code, instead of using a command button's event, use the Combo's Keypress event:Quote:
Originally Posted by dclamp
VB Code:
Option Explicit Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As String) As Long Private Const LB_FINDSTRINGEXACT = &H1A2 Private Const CB_FINDSTRINGEXACT = &H158 Private Const CB_FINDSTRING = &H14C Private Const LB_FINDSTRING = &H18F Private Sub Combo1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Dim lngRetVal As Long lngRetVal = SendMessageString(Combo1.hWnd, CB_FINDSTRINGEXACT, -1&, Combo1.Text) If lngRetVal = -1& Then _ Combo1.AddItem Combo1.Text End If End Sub
I don't understand how the navigate sub works but I assume that URL is the url that you navigated to. If that is true then the following is all you need.
VB Code:
Private Sub brwWebBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant) Dim lngRetVal As Long lngRetVal = SendMessageString(cmbAddress.hWnd, CB_FINDSTRINGEXACT, -1&, CStr(URL)) If lngRetVal > -1& Then ' The url is already in cmbAddress so don't add it again Else cmbAddress.AddItem CStr(URL) cmbAddress.ListIndex = 0 End If End Sub
Exactly Martin. :)Quote:
Originally Posted by MartinLiss