Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FileListBox

Posted on 2000-05-08
9
Medium Priority
?
475 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
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.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

721 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