Solved

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

Posted on 2004-04-10
5
445 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 49

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 49

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

13 Experts available now in Live!

Get 1:1 Help Now