The following event handler displays a dialog to pick a text file, then adds the contents of that file to a memo field. The date and time are written to the memo field before the added file.

PROCEDURE addTextButton_onClick

   local cFile, cCRLF 

   cCRLF = chr( 13 ) + chr( 10 ) 

   cFile = getfile( "*.txt", "Text file to import" ) 

   if "" # cFile 

      replace MEMO_FIELD with cCRLF + dtoc( date( )) + " " + time( ) + cCRLF additive 

      append memo MEMO_FIELD from ( cFile ) 

   endif 

The date and time, with a line break before and after, is written to the memo field using the REPLACE command with the ADDITIVE option for memo fields.

GETFILE( ) will return an empty string if no file is selected. In the IF statement, the order of the empty string and the variable cFile is important. If they were the other way around and SET EXACT is OFF, then the IF statement would always be false.

The parentheses are used as indirection operators to get the name of the file from the variable. Without them, dBASE Plus would attempt to append a file named cFile.