Solved

ListBox

Posted on 2000-05-13
6
255 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
[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 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
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.

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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
Course of the Month4 days, 5 hours left to enroll

630 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