Solved

ListBox

Posted on 2000-05-13
6
246 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
Comment Utility
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
Comment Utility
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
Comment Utility
DrDelphi <--- Never met an "Answer" button he didn't like.. <lol>.

DrDelphi: Where is the listbox the questioner requests?.. <smile>.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:sgianniotis
Comment Utility
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
Comment Utility
..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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now