aidanmcg33
asked on
Visual Basic Folders
How can i get my application to populate a list box with a list of all the folders that exist in the application path. so say ive got folder1, folder2, and folder3.
i want the list box to have:
folder1
folder2
folder3
i want then to have it so that when i click on folder1 in the list box, that a picture appears in the picture box on the right that is called folder1.jpg and a text box to populate with a file called text.txt thanks. if i can get this solved within the next 12 hours ill try offer more points if possible
i want the list box to have:
folder1
folder2
folder3
i want then to have it so that when i click on folder1 in the list box, that a picture appears in the picture box on the right that is called folder1.jpg and a text box to populate with a file called text.txt thanks. if i can get this solved within the next 12 hours ill try offer more points if possible
ASKER
got this code:
Path = "J:\DVD\"
Subdir = Dir(Path, vbDirectory)
Do While Len(Subdir)
If (GetAttr(Path & Subdir) And vbDirectory) Then
lstFilms.AddItem Subdir
End If
Subdir = Dir
Loop
how do i get it to change the picture in the picture box by whats in the folder?
Path = "J:\DVD\"
Subdir = Dir(Path, vbDirectory)
Do While Len(Subdir)
If (GetAttr(Path & Subdir) And vbDirectory) Then
lstFilms.AddItem Subdir
End If
Subdir = Dir
Loop
how do i get it to change the picture in the picture box by whats in the folder?
"when i click on folder1 in the list box, that a picture appears in the picture box on the right that is called folder1.jpg and a text box to populate with a file called text.txt"
Did you by chance mean text1.txt instead of text.txt? So if you clicked on Folder2 then you would want folder2.jpg and text2.txt?
Where are these files located? Are they also in the app path? ...or are they located within each respective subfolder?
Did you by chance mean text1.txt instead of text.txt? So if you clicked on Folder2 then you would want folder2.jpg and text2.txt?
Where are these files located? Are they also in the app path? ...or are they located within each respective subfolder?
ASKER
Dim Path As String
Dim Subdir As String
Private Sub Form_Load()
Path = "J:\DVD\"
Subdir = Dir(Path, vbDirectory)
Do While Len(Subdir)
If (GetAttr(Path & Subdir) And vbDirectory) Then
lstFilms.AddItem Subdir
End If
Subdir = Dir
Loop
End Sub
Private Sub lstFilms_Click()
Dim temp As String
Dim handle As Integer
On Error GoTo error:
temp = lstFilms.Text
picpath = Path & Subdir & temp & "\" & temp & ".jpg"
imgPicture.Picture = LoadPicture(picpath)
lblDescription.Caption = "Descrition: " & temp
despath = Path & Subdir & temp & "\Description.txt"
txtDescription.Text = FileText(despath)
error:
End Sub
Function FileText(ByVal filename As String) As String
Dim handle As Integer
If Len(Dir$(filename)) = 0 Then
Err.Raise 53
End If
handle = FreeFile
Open filename$ For Binary As #handle
FileText = Space$(LOF(handle))
Get #handle, , FileText
Close #handle
End Function
Dim Subdir As String
Private Sub Form_Load()
Path = "J:\DVD\"
Subdir = Dir(Path, vbDirectory)
Do While Len(Subdir)
If (GetAttr(Path & Subdir) And vbDirectory) Then
lstFilms.AddItem Subdir
End If
Subdir = Dir
Loop
End Sub
Private Sub lstFilms_Click()
Dim temp As String
Dim handle As Integer
On Error GoTo error:
temp = lstFilms.Text
picpath = Path & Subdir & temp & "\" & temp & ".jpg"
imgPicture.Picture = LoadPicture(picpath)
lblDescription.Caption = "Descrition: " & temp
despath = Path & Subdir & temp & "\Description.txt"
txtDescription.Text = FileText(despath)
error:
End Sub
Function FileText(ByVal filename As String) As String
Dim handle As Integer
If Len(Dir$(filename)) = 0 Then
Err.Raise 53
End If
handle = FreeFile
Open filename$ For Binary As #handle
FileText = Space$(LOF(handle))
Get #handle, , FileText
Close #handle
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER