>************************************************************ >*function File_Chooser >* Author............: George Tasker >* Description...... : Function invokes MS Common Dialog Control and >* : returns an array of files via parameters list. >* : Each element of the array contains one file... >* Calling Samples...: dimension a_File[1] >* : lcPath = "" >* : lnFiles = File_Chooser(@a_File, @lcPath, DTitle, InDir) >* Parameter List....: a_File, pPath, DTitle, InDir >******************************************************************** >*---------------------------------------------------------------------------------- >*!* the below EXAMPLE code will call this function and get all 02*.dbf files in \programnotes >*!* Don't forget to change the filter in the code in this function to determine what you >*!* want to search for! >*---------------------------------------------------------------------------------- >*!* * Calling Example for 02*.dbf files: >*!* >*!* dimension a_File[1] >*!* lcPath = "" >*!* DTitle="Please select a file" >*!* InDir="\programnotes" && change this line to your directory where 02*.dbf is located >*!* lnFiles = filechooser(a_File, lcPath, DTitle, InDir) >*!* >*------------------------------ >* NOTE: the following also works in the current directory: >* LocFile("02*","dbf") >*---------------------------------------------------------------------------------- >lparameter a_File, lcPath, DTitle, InDir >external array a_File > >** Definition of Common Dialog flags > >#define cdlOFNAllowMultiselect 0x200 >*!* Specifies that the File Namelist box allows multiple selections. >*!* The user can select more than one file at run time by pressing >*!* the SHIFT key and using the UP ARROW and DOWN ARROW keys to select the desired files. >*!* When this is done, the FileName property returns a string containing the names >*!* of all selected files. >*!* The names in the string are delimited by spaces. >local oDialog >oDialog = createobject('MSComDlg.CommonDialog') >* Set the flags for Multi-Select/Explorer >with oDialog > .MaxFileSize = 260 > .Flags = 0x200 + 0x80000 > .DialogTitle=DTitle >* Set filters > *^^tch set filter below > .Filter = "02 Tables (02*.dbf)|02*.dbf" > *.filter = "All Files (*.*)|*.*|Database Files (*.dbf)|*.dbf|Index Files (*.cdx)|*.cdx" >* Specify default filter > .FilterIndex = 1 > > if not empty(m.InDir) > .InitDir=m.InDir > endif > > .ShowOpen > >* Save the file name to a variable > lcFileName = .FileName >endwith >oDialog = null > >if empty(m.lcFileName) > *&& User pressed a Cancel > return 0 >endif > >lnpt = at(chr(0), m.lcFileName) >if lnpt > 0 > lcPath = left(lcFileName, lnpt - 1) > lcFileName = substr(lcFileName, lnpt + 1) > lnFiles = occurs(chr(0), lcFileName) + 1 > dimension a_File[lnfiles] > lnI = 0 > do while not empty(lcFileName) > lnI = lnI + 1 > lnpt = at(chr(0), lcFileName) > if lnpt > 0 > lcname = left(lcFileName, lnpt - 1) > lcFileName = substr(lcFileName, lnpt + 1) > else > lcname = lcFileName > lcFileName = "" > endif > a_File[lni] = lcname > enddo > lnFiles = alen(a_File, 1) > FOR lni = 1 TO lnlast > ? a_file[lni] > NEXT >else > lnFiles=1 > dimension a_File[lnFiles] > lnPos=rat('\',lcFileName) > lcPath=left(lcFileName,lnPos-1) > lcname=substr(lcFileName,lnPos+1) > a_File[1] = lcname >ENDIF >return lnFiles >>