Solved

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

Posted on 2004-04-10
5
451 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
[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 52

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 52

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

705 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