Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FileListBox

Posted on 2000-05-08
9
Medium Priority
?
476 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 800 total points
ID: 2812055
I assume this answered your question
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

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…
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…
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 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…
Suggested Courses

963 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