Solved

ListBox

Posted on 2000-05-13
6
250 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
Industry Leaders: 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!

 

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

Industry Leaders: 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!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

685 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