Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
as I said "append from ? sdf" works perfectly fine
tried "append from ? sdf", but it is confusing users with it's .txt extension.
Even better, store the return value of Getfile() into a memory variable and validate it before passing it to the command
Using commands with ? is a hack of the language you can use as developer, I wouldn't ever use such a version of a command for end users.
How do we intercepting button clicks in FoxPro? What code for 'ESC'? Please be more informative, if you could.MikeLewis said:And this has the additional advantage that you can (and should) trap the user pressing ESC to cancel the import.
Why not? What should we use instead? Please be more specific.danfreeman's said:More specifically, using ? in a command like APPEND FROM (or USE or CD, etc.) is intended for interactive use. It's for *us*. It's not meant for end-users of finished applications.
Why not? What should we use instead? Please be more specific.
VFP Help Topic on GETFILE said:GETFILE( ) returns the name of the file chosen in the Open dialog box or the empty string if the user closes the Open dialog box by pressing ESC, clicking Cancel or the Close button on the Open dialog box.
* --- Allow User to choose file to Import ---
mInputFile = GETFILE("DAT") && Limit files shown to [b]".DAT"[/b] file type (or anything else)
IF !EMPTY(mInputFile)
* --- User chose fully pathed file name ---
* < Here You [u]COULD[/u] use FOPEN() to read the first row and ensure that the file content was formatted correctly >
* < If you do make sure you do the FCLOSE() as well >
* < [u]But that is not Required[/u] >
* --- Input file data is in the correct format (or assumed to be correct) and do the Import ---
SELECT RecipientTable
APPEND FROM (mInputFile) SDF
ELSE
* --- User clicked ESC or pressed CANCEL, Do Not Attempt Import ---
* < do whatever >
ENDIF
How do we intercepting button clicks in FoxPro? What code for 'ESC'? Please be more informative, if you could.
Try
filepath=Getfile('dat')
Catch
Wait Window 'No data file. Try again'
Finally
Clear Events
Endtry
If File(filepath)
gnDataFile = Fopen(filepath,0)
Else
Wait Window 'No data file. Try again'
Return
Endif
Try
filepath=Getfile('dat')
Catch
Wait Window 'No data file. Try again'
Finally
Clear Events
Endtry
filepath=Getfile('dat')
If Empty(filepath)
Wait Window "No file selected"
Return
Endif
gnDataFile = Fopen(filepath,0)
If gnDataFile < 0
Wait Window "File cannot be opened"
Return
Endif
filepath=Getfile('dat')
If Empty(filepath)
Wait Window Right(filepath,Len(filepath)-Rat('\',filepath))+" not found"
Return
else
Append from (filepath) sdf
Endif
cFileSelected = ""
DO WHILE EMPTY(cFileSelected)
cFileSelected = GETFILE("DAT")
IF EMPTY(cFileSelected)
mcMessageTitle = "Some Message Box Title"
mcMessageText = "You did not select a file";
+ CHR(13);
+ "Do you want to Exit/Quit This Routine?"
* --- OK Button Only ---
*nDialogType = 0 + 48 + 0
* 0 = OK Button Only
* 48 = Exclamation mark icon
* 0 = First button is default
* --- Yes/No Buttons ---
nDialogType = 4 + 32 + 256
* 4 = Yes and No buttons
* 32 = Question mark icon
* 256 = Second button is default
nAnswer = MESSAGEBOX(mcMessageText, nDialogType, mcMessageTitle)
IF nAnswer = 6
* --- YES - The User Elects To Exit/Quit Without Selecting File ---
EXIT
ENDIF
ELSE && IF EMPTY(cFileSelected)
* --- OK to Leave DO WHILE LOOP ---
EXIT
ENDIF && IF EMPTY(cFileSelected)
ENDDO && DO WHILE EMPTY(cFileSelected)
IF !EMPTY(cFileSelected)
SELECT RecipientTable
APPEND FROM (cFileSelected) SDF
ENDIF