Solved

ListBox

Posted on 2000-05-13
6
247 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 57
VB error "Type mismatch" 2 53
to transfer string from C lanaguage to VBA 4 64
Can we place a tooltip on the actual vb6 form 5 41
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 …
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…
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…

776 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