API File Search
Filedialogs
The FILES statement
The FILES statement in action
Open Source Editor for WinXP
Spotlight on John Fisher
Using Winsock
Winsock API Reference
This sample shows how to use the FILES statement to fill listboxes and comboboxes
to simulate a Windows filedialog.
The advantage to writing your own dialog of this type is that it can remain
open, and it can contain other controls. For instance, it might be used to
preview wav files by playing a wav when one is selected from the list. You
might include a graphicbox to create a bitmap previewer. The uses are many
for this type of window.
'some code by Ryan Jeffords, 1997
NoMainWin
Dim dir$(10,10)
Dim files$(300)
Dim directory$(300)
Dim Drive$(300)
Dim type$(5)
qu$ = Chr$(34)
view = 0
pathname$ = Mid$(DefaultDir$,3,Len(DefaultDir$))
unit$ = Left$(DefaultDir$,2)
fileext$ = "*.txt"
type$(1) = "Text Files (*.TXT)"
type$(2) = "Code Files (*.BAS)"
type$(3) = "Bitmap Files (*.BMP)"
type$(4) = "All Files (*.*)"
GoSub [scanfiles]
'** Set Window Attributes
UpperLeftX = Int((DisplayWidth- 447)/2)
UpperLeftY = Int((DisplayHeight- 246)/2)
WindowWidth = 447
WindowHeight = 246
'** Add Window Controls
Textbox #dirbox.filetext, 5, 20,170,25
Listbox #dirbox.filebox, files$(, [db.InputLoop],5,55,170,105
Combobox #dirbox.filetype, type$(, [db.filetype],5,185,170,165
Listbox #dirbox.dirbox, directory$(, [db.InputLoop],185,20,175,138
Combobox #dirbox.drivebox, Drive$(, [db.drivetype],185,185,175,80
Button #dirbox.Button12, "Ok", [db.ok] , UL,365,30,70,24
Button #dirbox.Button13, "Cancel", [db.CloseWindow],UL,364,56,70,24
statictext #dirbox.1, "File Types:",5,162,170,20
statictext #dirbox.2, "Drives:",185,162,170,20
statictext #dirbox.3, "File Names:",5,1,170,20
statictext #dirbox.4, "Folders:",185,1,170,20
'** Display window
Open "File Preview Dialog" For dialog As #dirbox
Print #dirbox, "TRAPCLOSE [db.CloseWindow]"
Print #dirbox, "font MS_Sans_Serif 0 16"; '** Set the font
Print #dirbox.filebox, "singleclickselect [db.choosefile]"
Print #dirbox.dirbox, "singleclickselect [db.choosedir]"
[db.AfterLoad]
Print #dirbox.drivebox, "select "; unit$
Print #dirbox.filetype, "select "; type$(1)
GoSub [redisplayfiles]
[db.InputLoop]
wait
[db.CloseWindow]
Close #dirbox : End
[db.Subroutines]
[redisplayfiles]
Print #dirbox.dirbox, "reload"
Print #dirbox.filebox, "reload"
Return
[scanfiles]
index = 0
loadname$ = unit$ + pathname$
Files loadname$, fileext$, dir$(
qtyFiles = Val(dir$(0, 0))
qtySubDirs = Val(dir$(0, 1))
ReDim files$(300)
For x = 1 TO qtyFiles
dir$(x,1) = Right$(dir$(x, 1), 9)
files$(x) = Left$(dir$(x, 0),13)
Next x
While Word$(Drives$, index + 1) <> ""
Drive$(index) = Word$(Drives$, index + 1)
index = index + 1
Wend
ReDim directory$(300)
directory$(0) = ". ."
For x = qtyFiles+1 TO qtyFiles + qtySubDirs
directory$(x) = " " + dir$(x, 1)
Next x
If qtyFiles > 2 Then Sort files$(, 1, qtyFiles
Return
[truncatename]
For z = Len(pathname$) TO 1 step -1
If Mid$(pathname$,z,1) = "\" Then pathname$ = Left$(pathname$, z-1): z = 0
Next z
If Instr(pathname$,"\") = 0 Then pathname$ = "\"
Return
[db.choosefile]
Print #dirbox.filebox ,"selection? selection$"
Print #dirbox.filetext, selection$
GoSub [redisplayfiles]
wait
[db.filetype]
Print #dirbox.filetype ,"selection? fileext$"
z = Instr(fileext$, "(")
fileext$ = Mid$(fileext$, z+1, Len(fileext$)-z-1)
GoSub [scanfiles]
GoSub [redisplayfiles]
wait
[db.choosedir]
Print #dirbox.dirbox ,"selection? newdir$"
If newdir$ <> ". ." AND Len(pathname$) > 2 Then
pathname$ = pathname$ + "\" + newdir$
Else
pathname$ = pathname$ + newdir$
End If
If newdir$ = ". ." Then GoSub [truncatename]
GoSub [scanfiles]
GoSub [redisplayfiles]
wait
[db.drivetype]
Print #dirbox.drivebox ,"selection? newunit$"
unit$ = newunit$ : pathname$ ="\"
GoSub [scanfiles]
GoSub [redisplayfiles]
wait
[db.ok]
Print #dirbox.filetext, "!Contents? TheName$";
Notice "Dir Info" +Chr$(13)+"File Name Selected :";TheName$+Chr$(13)+"Directory: "+loadname$
wait