1. RE: [WIN] recursion? (get two files via open file dialog)
Dan Moyer wrote:
> Arrgh! Not sure where/how my code got mangled, but here's what it
> SHOULD
> have been. My question is, is there anything wrong with this that I
> don't
> see? It works, but I've never deliberately used recursion before.
>
> Dan Moyer
>
> -- CODE BEGINS
>
> -- Get2files.exw
> -- gets just TWO files via open files dialog
>
> -- by Dan Moyer May 16, 2002
> -- based on an example by Derek Parnell
>
> -- code generated by Win32Lib IDE v0.10.6
> -- then hand modified
>
> include Win32lib.ew
> without warning
>
> 10, 16, 90, 30, 0 )
> global constant List3 = create( List, "List3", Window1, 10, 104, 396,
> 160,
> 0 )
> global constant AtextBox = create( LText, "", Window1, 10, 68, 400, 24,
> 0 )
>
>
> files = {}
> dirName = {}
> posSlash = 0
>
> files =
> penFileName(
> Window1, -- parent window
> "", -- no default name
> { "Dialog Flags", {OFN_ALLOWMULTISELECT},
> "Text File", "*.TXT", -- text files
> "All Files", "*.*" } ) -- everything else
>
> if length(files) = 0 then
> return -- no file(s) selected, so re-ask until either select or close
> end if
>
> if not sequence( files[1]) then -- just selected ONE file:
> dirName = files -- at this point has full pathname
>
> posSlash = 0
> for p = length(dirName) to 1 by -1 do
> if equal('\\', dirName[p]) then
> posSlash = p
> exit
> end if
> end for
>
> -- separate the dirname from the filename:
> files = dirName[posSlash+1..length(dirName)] -- the file name
> dirName = dirName[1..posSlash-1] -- the dirname
>
> else -- must have selected more than one file:
>
> dirName = files[1] -- get directory name
> dirName = dirName[1..length(dirName)-1] -- remove trailing "\"
> files = files[2 .. length(files)] -- get all file names
>
> -- but only allow TWO to be selected:
> if length(files) > 2 then
> setText(AtextBox, "")
> eraseItems(List3)
> dirName = {}
> files = {}
> setText(Window1, "Select no more than TWO Files")
> GetFilesButton_onClick () -- RECURSION??
> return
> end if
> end if
>
> setText(Window1, "Gets one or TWO files")
> -- now use the info:
> setText(AtextBox, dirName)
> eraseItems(List3)
> addItem(List3, files) -- ONE addItem adds ALL items in "files"!
>
> end procedure
>
> onClick[GetFilesButton] = routine_id("GetFilesButton_onClick")
>
>
> WinMain( Window1, Normal )
>
>
> ----- Original Message -----
> From: "Dan Moyer" <DANIELMOYER at prodigy.net>
> To: "EUforum" <EUforum at topica.com>
> Sent: Thursday, May 16, 2002 6:07 PM
> Subject: [WIN] recursion? (get two files via open file dialog)
>
<snip>
it might be better to use a WHILE loop rather than recursion, in order
to reduce potenial memory usage.
Something like...
files = {}
while length(files) != 2 do
Get User Selections
Grab files from user selections.
if more than 2 files chosen then
Message "Please select only two files."
elsif less than 2 files chosen then
Message "You must choose two files."
end if
end while
--------
Derek