Solved

ListBox

Posted on 2000-05-13
6
248 Views
Last Modified: 2010-05-02
In VB4 I have a form (frm1),  with a ListBox (List1), and an Image (Img1).
There is also a DirListBox (Dir1) and a DriveListBox (Drive1).
I want to select any directory of pictures from my Hard-Disk, to view the names of the picture-files in the ListBox (List1), and to view the pictures in the Image (Img1), by making a click in their names in the ListBox.
0
Comment
Question by:sgianniotis
6 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 2806770
And your question is?

When the directory changes, clear the list box and search for files with a given name using the DIR() command. If the function returns a string, add it to the list box.

In the _Click event of the list box grab the file name and use LoadPicture() to get the image.

M
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2806771
Private Sub Dir1_Change()
File1.Path = Dir1.Path


End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive


End Sub

Private Sub File1_Click()
ImG1.Picture = LoadPicture(Dir1.Path & "\" & File1.filename)
End Sub

Private Sub Form_Load()

End Sub
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2806821
DrDelphi <--- Never met an "Answer" button he didn't like.. <lol>.

DrDelphi: Where is the listbox the questioner requests?.. <smile>.
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:sgianniotis
ID: 2806899
The question is:
1) How will be shown the files in the ListBox?  How can they appear?

2) How could I present the pictures in the    ImageControl (Img1), by a click on their names in the ListBox?

The above answer of MrDelphi does not work, as there is no FileListBox!
0
 
LVL 12

Accepted Solution

by:
jgv earned 75 total points
ID: 2807091
..then you should reject DrDelphi's answer :)

Try this and see if it's what you're looking for...

Option Explicit
Dim PathSep As String

Private Sub Dir1_Change()
Dim retfile As String
Dim ValidFiles As String

'//clear the image control and the listbox
List1.Clear
Img1.Picture = LoadPicture()

'//add the extension for the filetypes you want to appear in the
'//listbox to this string
ValidFiles = "jpg, bmp, ico"

'//the following avoids an error if you select a root directory
PathSep = "\"
If Right(Dir1.Path, 1) = "\" Then PathSep = ""

'//loop through all the files in the selected directory and check
'//for the file extension in "ValidFiles". If found, add the file to the listbox
retfile = Dir(Dir1.Path & PathSep & "*.*")
Do While retfile <> ""
    If InStr(1, ValidFiles, LCase(Right(retfile, 3))) Then List1.AddItem retfile
    retfile = Dir
Loop
End Sub

Private Sub List1_Click()
Img1.Picture = LoadPicture(Dir1.Path & PathSep & List1.List(List1.ListIndex))
End Sub
0
 

Author Comment

by:sgianniotis
ID: 2807126
The answer of MrDelphi does not work, as there is no FileListBox!

The answer of iqv does work and I accept it!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

831 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