Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-10
5
Medium Priority
?
455 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

604 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