1. [WIN] recursion? (get two files via open file dialog)

The following intends to be a demo for Win32Lib (version 0.57.5), to get
multiple files via open file dialog, but specifically only up to TWO files;
I think I have used "recursion" in it (haven't deliberately done so before),
and it appears to work fine, but I'm wondering if there might be something
wrong with it that I don't see (like memory leakage or something)?

Dan Moyer

-- CODE BEGINS

--  Get2files.exw
--  gets one or 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 eit
her 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 )

new topic     » topic index » view message » categorize

2. Re: [WIN] recursion? (get two files via open file dialog)

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)


>
> The following intends to be a demo for Win32Lib (version 0.57.5), to get
> multiple files via open file dialog, but specifically only up to TWO
files;
> I think I have used "recursion" in it (haven't deliberately done so
before),
> and it appears to work fine, but I'm wondering if there might be something
> wrong with it that I don't see (like memory leakage or something)?
>
> Dan Moyer
>
<<SNIPPED MANGLED CODE>>

new topic     » goto parent     » topic index » view message » categorize

3. Re: [WIN] recursion? (get two files via open file dialog)

Thanks Derek,  I'll give it a try.

Dan

<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
> 
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu