Solved

FileListBox

Posted on 2000-05-08
9
473 Views
Last Modified: 2010-05-18
In a VB4 programm there is a FileListBox,
named File1.
This FileListBox shows the files that exist in a certain directory.
The files are: Readme.txt, Win.zip, Foto.jpg
How could be the names of these files to be shown  in the FileListBox
with uppercase letters and without extension?
Like this: README, WIN, FOTO.
0
Comment
Question by:ote
[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
  • 6
  • 2
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2789107
i dont think you will want to use a filelistbox in this case, but rather, a true list box in which you can manipulate the appearance the way you want to
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2789194
Place a filelistbox and a listbox on the form. Add the following code to the form. This is how you can hide the extensions and use uppercase letters.



Option Explicit

Private Function LastInStr(ByVal String1 As String, ByVal String2 As String, Optional ByVal Start As Long = 0, Optional Compare As VbCompareMethod = vbBinaryCompare) As Long
    LastInStr = Start
    While InStr(LastInStr + 1, String1, String2, Compare)
        LastInStr = InStr(LastInStr + 1, String1, String2, Compare)
    Wend
End Function

Private Sub CopyLists(lstBoxDest As ListBox, filListBoxSrc As FileListBox)
    Dim I As Integer, S As String
    Call lstBoxDest.Clear
    For I = 0 To filListBoxSrc.ListCount - 1
        S = filListBoxSrc.List(I)
        S = UCase$(Left(S, LastInStr(S, ".") - 1))
        Call lstBoxDest.AddItem(S)
    Next
End Sub

Private Sub File1_PathChange()
    Call CopyLists(List1, File1)
End Sub

Private Sub File1_PatternChange()
    Call CopyLists(List1, File1)
End Sub

Private Sub Form_Load()
    Dim I As Long
    File1.Visible = False
    Call CopyLists(List1, File1)
End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2789281
i assume you have a dirlistbox working in conjunction here...in that case it can all be done in one routine:


Private Sub Dir1_Change()
    Dim filesys, f, files, fileObj As Object
    Dim path, tempStr As String
    Dim pos As Long
    List1.Clear
    path = Dir1.path
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set f = filesys.GetFolder(path)
    Set files = f.files
    For Each fileObj In files
        pos = InStr(1, fileObj.Name, ".")
        tempStr = Left(fileObj.Name, pos - 1)
        tempStr = UCase(tempStr)
        List1.AddItem tempStr
    Next
End Sub


Now the listbox acts just like the filelistbox but the way you want it to

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2789338
also note you dont need a filelistbox on your form at all with this method
0
 

Author Comment

by:ote
ID: 2790181
A comment to AsraSound

I think your  2nd answer could help me.

The FileListBox in my programm, contains
pictures files (.jpg) which by the next lines in:

Private Sub File1_Click()

f$ = File1.Path + "\" + File1.filename
Image1.Picture = LoadPicture(f$)

are shown as image in the form.

With the  "Private Sub Dir1_Change()"
you sent me, the names of picture files are shown
indeed with uppercase letters and without extensions exactly as I like.

The problem that I have now is how can I select
the files from the ListBox.
Thank you
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790230
create an array to hold the "true" filenames...for example:



Dim arr As Variant
Dim i As Integer

Private Sub Dir1_Change()
    ReDim arr(0) As Variant
    i = 0
    Dim filesys, f, files, fileObj As Object
    Dim path, tempStr As String
    Dim pos As Long
    List1.Clear
    path = Dir1.path
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set f = filesys.GetFolder(path)
    Set files = f.files
    For Each fileObj In files
        pos = InStr(1, fileObj.Name, ".")
        tempStr = Left(fileObj.Name, pos - 1)
        tempStr = UCase(tempStr)
        List1.AddItem tempStr
        arr(i) = fileObj.Name
        ReDim Preserve arr(i + 1)
        i = i + 1
    Next
End Sub

Private Sub List1_Click()
    Dim item As Integer
    item = List1.ListIndex
    MsgBox arr(item)
End Sub


now everytime you click on the listbox a msgbox will pop up showing the actual filename...you can alter it a bit to suit your needs (i.e. to open the file)

0
 

Author Comment

by:ote
ID: 2792579
What I am looking for is:

1) I have some picture-files (.jpg) existing in the folder c:\icons\  
2) In the form there is an ImageControl
3) The names of the picture-files are shown in a ListBox.

How could I present the pictures in the ImageControl by a click on their names in ListBox?

Thanks
 
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2792909
ok using the method i pointed to earlier...you should be able to use

Dir1.Path & arr(item) for the full path


Now you can load it as follows,


Private Sub List1_Click()
    Dim item As Integer
    item = List1.ListIndex
    Set Image1.Picture = LoadPicture(Dir1.Path & arr(item))
End Sub




0
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 2812055
I assume this answered your question
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

628 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