Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getfile()
Message
From
08/02/2002 09:38:17
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Miscellaneous
Thread ID:
00616954
Message ID:
00617311
Views:
84
Tim, this works. Thanks to George Tasker (he wrote it), I use it alot:
************************************************************
*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
>>Tim,
>>
>>No, I'm saying is that I think MS Common Dialog is the more conventional way of doing it. It is part of the Windows platform SDK. getfile() is a function provided with VFP, and it has been around for a while.
>>
>>>
>>>so what you're saying, there's no conventional way of doing this, so Nadya's prg kind of simulates the true getfile()? I got it to work using below code.
>>>
>
>Getting back to my orig quest, is there a way for getfile() to show only files of my choice beginning with a prefix like 020*.dbf rather than all dbfs()?
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform