Home  |  Programs  |  Tips & Tricks  |  Subs & Functions  |  Links  |  Laz's Liberty Basic Site


Make the open or save dialog box remember the last path it was on

'we don't need a main window
nomainwin

'set the window position
WindowWidth = 285 : WindowHeight= 130
UpperLeftX = (DisplayWidth-WindowWidth)/2
UpperLeftY = (DisplayHeight-WindowHeight)/2


'add a button with the label "Select File"
button #main.button, "Select File", [button], UL, 10,10,100,25

'open the window
open "Window" for window as #main

'tell Liberty Basic to goto [quit] when the X is clicked at the top of the window
print "trapclose [quit]"



wait

[quit]
'close the window
close #main
end


[button]
'code to run when the button is clicked
filedialog "Open a file",Path$,FileName$
if Path$ <> "" then Path$ = FileName$
wait


The lines that make this tip work are these two.
filedialog "Open a file",Path$,FileName$
if Path$ <> "" then Path$ = FileName$

Setting the Path$ to the return value of the filedialog function will ensure that the next time the file dialog function is called it will start in the last place that a file was opened. On the other hand, if the user cancels instead of opening a file then the next time the filedialog function is called then it will act the same as the first time. If you have more than one place that you want to have the user open and/or save a file, or if you are going to use more than one filedialog command in a single program then you need to make shure that the variable name you use won't get changed somewhere else in the program name. You could use something like Open1$, or Browse1$.

Hosted by www.Geocities.ws

1