Solved

How to remove file extensions from files listed in a FileListBox?

Posted on 2004-04-10
5
447 Views
Last Modified: 2010-05-02
I have the following code which populates a 'FileListBox' with .html files. I want the user to only see the files without the .html extensions.

Private Sub Form_Load()
File1.Pattern = "*.html"
File1.Path = "\\fsis02\vol2\group0k\Ricky\MSRVBA_BK"
End Sub

Private Sub File1_DblClick()
Dim fPath As String
If Right$(File1.Path, 1) <> "\" Then
    fPath = File1.Path & "\"
Else
    fPath = File1.Path
End If

WebBrowser1.Navigate (fPath & File1.List(File1.ListIndex))
End Sub

Any ideas,
Rich

0
Comment
Question by:rkckjk
5 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 50 total points
ID: 10797449
Try this:

Private Sub Form_Load()
File1.Pattern = "*.html"
File1.path = "\\fsis02\vol2\group0k\Ricky\MSRVBA_BK"
File1.Visible = False
List1.Clear
For i = 0 To File1.ListCount - 1
    List1.AddItem Replace$(File1.List(i), Replace$(File1.Pattern, "*", ""), "")
Next i
End Sub

Private Sub List1_DblClick()
    ClickItem List1.ListIndex
End Sub

Private Sub ClickItem(Index As Integer)
    If Index = -1 Then Exit Sub
    Dim fPath As String
    If Right$(File1.path, 1) <> "\" Then
        fPath = File1.path & "\"
    Else
        fPath = File1.path
    End If
   
    WebBrowser1.Navigate (fPath & File1.List(Index))
End Sub

cheers
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 10797456
Forget to tell, the above example need add an additional ListBox Control (List1), and that's hide the exact FileListBox Control, and then replace with the ListBox, where we can customize the content to display.

cheers
0
 
LVL 2

Author Comment

by:rkckjk
ID: 10797504
I'm using VB 5.0 which doesn't have the 'replace' function ability.

Thanks,
Rich
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10797674
Using the same method as ryancys, you can use Left/Right/Mid to remove the unwanted characters. FileListBox's Item() is read-only so not sure of any other methods.

Have FileListBox (File1) and ListBox (List1) and try. Change the Form_Load's .Path to suit your needs.

Private Sub Form_Load()
    File1.Path = "c:\"
    File1.Pattern = "*.html"
    Call HideExtensions(File1, List1, ".html")
End Sub
Private Sub HideExtensions(ByRef FileList As FileListBox, ByRef ListBox As ListBox, ByVal sExt As String)
    Dim iLoop As Integer
    Call ListBox.Clear
    For iLoop = 0 To FileList.ListCount - 1
        If Right(LCase(FileList.List(iLoop)), Len(sExt)) = LCase(sExt) Then
            Call ListBox.AddItem(Left(FileList.List(iLoop), Len(FileList.List(iLoop)) - Len(sExt)))
        End If
    Next iLoop
End Sub
0
 
LVL 7

Expert Comment

by:Burbble
ID: 10797763
http://www.andreavb.com/tip110003.html



Public Function Replace(ByVal strString As String, ByVal _
strReplaceWith As String, ByVal strReplace As String) As String
'*************************************************************
'* Replicates the Replace Function found in Visual Basic 6.0
'* Usage: For VBA programming Word Macro etc
'* MyVar = Replace("Greg Hello World Greg", "David", "Greg")
'*************************************************************
    Dim i As Long
    Dim strTemp As String

    i = 1
    Do While InStr(i, strString, strReplace, vbTextCompare) <> 0
        strTemp = strTemp & Mid(strString, i, InStr(i, _
            strString, strReplace, vbTextCompare) - i) & strReplaceWith
        i = InStr(i, strString, strReplace, vbTextCompare) + Len(strReplace)
    Loop
    strTemp = strTemp & Right(strString, Len(strString) - i + 1)
    Replace = strTemp
End Function



-Burbble
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 53
MS Acccess - Update Field in Table when report is printed 6 44
message box in access 4 46
Advice in Xamarin 21 78
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now