|
-
Jan 8th, 2008, 07:10 PM
#1
Thread Starter
Frenzied Member
Populating ListBox With IE Favorites
I want to import all the IE favorites & populate them in a ListBox but if an IE favorite already is marked as a favorite in my browser, that favorite should not be listed in the ListBox. When users click a menu item, the ListBox should be populated. This is how I tried it:
Code:
'all the APIs & Constants come here
Private Sub mnuIEFav_Click()
Dim FavPath As String
Dim FP As FILE_PARAMS
FavPath = GetFolderPath(CSIDL_FAVORITES)
If (Len(FavPath) > 0) Then
With FP
.sFileRoot = FavPath
.sFileNameExt = "*.url"
.bRecurse = True
End With
'get the files
Call SearchForFiles(FP)
End If
End Sub
Private Function SearchForFiles(FP As FILE_PARAMS) As Double
Dim hFile As Long
Dim sTmp As String
Dim sPath As String
Dim sRoot As String
Dim WFD As WIN32_FIND_DATA
sRoot = QualifyPath(FP.sFileRoot)
sPath = sRoot & "*.*"
'obtain handle to the first match
hFile = FindFirstFile(sPath, WFD)
'if valid
If (hFile <> INVALID_HANDLE_VALUE) Then
Call GetFileInformation(FP)
Do
'if the returned item is a folder
If ((WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY)) Then
If (FP.bRecurse) Then
If (sTmp <> "." And sTmp <> "..") Then
FP.sFileRoot = sRoot & sTmp
Call SearchForFiles(FP)
End If
End If
End If
'continue looping until FindNextFile returns 0 (no more matches)
Loop While FindNextFile(hFile, WFD)
'close the find handle
hFile = FindClose(hFile)
End If
End Function
Private Function GetFileInformation(FP As FILE_PARAMS) As Long
Dim pos As Long
Dim hFile As Long
Dim sTmp As String
Dim sUrl As String
Dim sPath As String
Dim sRoot As String
Dim FileName As String
Dim sShortcut As String
Dim blnFavURL As Boolean
Dim iFile As Integer
Dim i As Integer
Dim WFD As WIN32_FIND_DATA
sRoot = QualifyPath(FP.sFileRoot)
sPath = sRoot & FP.sFileNameExt
i = 0
hFile = FindFirstFile(sPath, WFD)
If (hFile <> INVALID_HANDLE_VALUE) Then
Do
If Not ((WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) Then
pos = InStr(sTmp, ".url")
If (pos > 0) Then
sShortcut = Left$(sTmp, pos - 1)
sUrl = ProfileGetItem("InternetShortcut", "URL", "", sRoot & sTmp)
blnFavURL = IfExistsURL(Trim(sUrl))
If (blnFavURL = False) Then
List1.AddItem sShortcut
Else
MsgBox sUrl & vbNewLine & "The above URL already exists!"
End If
End If
End If
Loop While FindNextFile(hFile, WFD)
'close the handle
hFile = FindClose(hFile)
End If
End Function
Function IfExistsURL(URL As String) As Boolean
Dim FavURLs As String
Dim i As Integer
For i = 0 To mnuFavSites.UBound
FavURLs = mnuFavSites(i).Tag
If (LCase(URL) = LCase(FavURLs)) Then
IfExistsURL = True
Exit Function
End If
Next i
End Function
Private Function QualifyPath(sPath As String) As String
If (Right$(sPath, 1) <> "\") Then
QualifyPath = sPath & "\"
Else
QualifyPath = sPath
End If
End Function
The problem is when the menu item is clicked for the first time, the ListBox gets populated with all the IE favorites that don't exist in my browser's favorites but if the menu item is clicked again, the ListBox again gets populated with the IE favorites i.e. the ListBox lists duplicate items.
For e.g. when the menu item is clicked for the first time, assume that 10 favorites get populated in the ListBox. If the menu item is clicked again, the same favorites again get added in the ListBox & hence the no. of items in the ListBox doubles to 20 where as it should have only 10 items.
How do I ensure that duplicate favorites do not get added in the ListBox?
I know that the following code will ensure that there aren't any duplicates in a ListBox but I don't know why it isn't working:
Code:
For i = 0 To List1.ListCount - 1
For j = 0 To List1.ListCount - 1
If (List1.List(i) = List1.List(j)) Then
List1.RemoveItem j
End If
Next
Next
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|