Drvlistbox, dirlistbox, filelistbox

i980565 Messages postés 4 Date d'inscription mardi 22 juillet 2003 Statut Membre Dernière intervention 25 juillet 2003 - 25 juil. 2003 à 11:30
cs_rene38 Messages postés 1858 Date d'inscription samedi 29 juin 2002 Statut Membre Dernière intervention 17 octobre 2013 - 25 juil. 2003 à 18:00
Hi everyone,

I'm trying to create my own file explorer (or however you want to call it). I already created a drvlistbox, a dirlistbox, a filelistbox, a textbox (to specify *.*), 3 labels (displaying the path, etc.) and a button (which will perform the *.*). I now want to include either a button which will open the selected file, or just the possibility to dblclick on the file to open it. However, I have no clue how to do this. Could somebody help me out with this (I would appreciate it if you are as specific as possible, I'm only a beginner!).

This is my code untill now!

Private Sub Form_Load()
With lblTitle
.Caption = "DRIVE LIST BROWSER"
.FontSize = 14
.ForeColor = &HFF&
.Alignment = 2
End With
With lblNumFiles
'total number of elements inside the list..
.Caption = FilList.ListCount & " files"
.FontBold = True
.WordWrap = True
End With
With lblExtension
.Caption = "Type of File to View"
.FontBold = True
End With
With TxtExtension
.Text = "*.*"
.FontBold = True
End With
DirDirectory.Path = "D:\database\Brieven"
CmdExtension.Caption = "&View"

End Sub

----

Private Sub drvFile_Change()
Dim Msg, Msg1 As String
Msg = "Please insert disc inside A:"
Msg1 = "Please insert CD ROM"
On Error GoTo IF_FILE_NOT_THERE
DirDirectory.Path = drvfile.Drive
Exit Sub

IF_FILE_NOT_THERE:
Select Case drvfile.Drive

Case "a:": MsgBox Msg, , "No A:\ DRIVE"
Case "d:": MsgBox Msg1, , "No CD ROM"
End Select
drvfile.Drive = DirDirectory.Path
End Sub

---

Private Sub dirDirectory_Change()
FilList.Path = DirDirectory.Path
lblNumFiles.Caption = FilList.ListCount _
& " files in " & DirDirectory.Path
End Sub

----

Private Sub cmdExtension_Click()
If (Left(TxtExtension.Text, 2)) <> "*." _
Or Len(TxtExtension.Text) = 0 Then
MsgBox "Just add extension"
TxtExtension.Text = "*."
TxtExtension.SelStart = 2
Else
FilList.Pattern = TxtExtension.Text
End If
End Sub

---

Private Sub button1_Click()

????????????

End Sub
----
and/or
---
filllist??

OK, this is my code, hopefully could help me out!!

Thanx

3 réponses

cs_rene38 Messages postés 1858 Date d'inscription samedi 29 juin 2002 Statut Membre Dernière intervention 17 octobre 2013 11
25 juil. 2003 à 14:41
Hi

To open a file, you need only :
- a drivelistbox ( Name = Drive1 )
- a dirlistbox ( Name = Dir1 )
- a filelistbox (Name = File1)

and the following code :

Dim MyFile As String ' In the 'General - Declarations' section OR
Public MyFile As String ' In a module

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub File1_DblClick()
Dim F As Integer
F = FreeFile
MyFile = File1.Path & "" & File1.FileName
Open MyFile For ****** As #F
End Sub

'Replace ***** with Input, Output, Append, Binary, Random as you need.
0
i980565 Messages postés 4 Date d'inscription mardi 22 juillet 2003 Statut Membre Dernière intervention 25 juillet 2003
25 juil. 2003 à 15:36
Hi,

thanx for your reply. Unfortunately, it does not work. When plugging in each of the parts you said (of course not all together), it does not open anything. Are you sure this is the right code?

thanx again
0
cs_rene38 Messages postés 1858 Date d'inscription samedi 29 juin 2002 Statut Membre Dernière intervention 17 octobre 2013 11
25 juil. 2003 à 18:00
Absolutely sure !
To verify it, you can add a textbox with the property MultiLine True (Name of the textbox Text1) and modify the code as follows (choose a .text file) :

Private Sub File1_DblClick()
Dim F As Integer, Words As String
F = FreeFile
MyFile = File1.Path & "" & File1.FileName
Open MyFile For Input As #F
Do While Not EOF(F)
Line Input #F, Words
Text1.Text = Text1.Text & Words & vbCrLf
Loop
Close F
End Sub

If you double click on a file name in the filelistbox, the content of the chosen file will be displayed in the textbox.
0
Rejoignez-nous