?
Solved

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

Posted on 2004-04-10
5
Medium Priority
?
453 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:Richard Kreidl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 200 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 53

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:Richard Kreidl
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 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