Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
StrToFile Equivalent in FPD26?
Message
From
18/02/2003 17:11:05
 
 
To
15/02/2003 09:27:06
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Miscellaneous
Thread ID:
00751416
Message ID:
00754686
Views:
18
Thanks Claudio,
I actually came up with something very similar:
*!****************************************************************************************************************
* codefile.prg
*!****************************************************************************************************************
* Example only
* Creates a table that stores a code name and code code
* Allows program code to be compiled and run on the fly by seeking
* the program name to run (stored in cprogram character field) and running the
* associated code (stored in mcode memo field)
*
SET TALK OFF
CLEAR
IF FILE('codefile.dbf')
	DELETE FILE ('codefile.dbf')
ENDIF
IF FILE('codefile.cdx')
	DELETE FILE ('codefile.cdx')
ENDIF
IF FILE('codefile.fpt')
	DELETE FILE ('codefile.fpt')
ENDIF
lcFileName = SYS(2015)	&& sys(2015) is more reliable than sys(3) for faster computers
lcDelete=lcFileName + ".fxp"
lcFileName=lcFileName+".prg"
#IF 'VISUAL' $ UPPER(VERSION())
	SET SAFETY OFF
	SELE 0
	CREATE TABLE codefile FREE (cprogram c(15), mcode m)
	INDEX ON cprogram TAG cprogram
	SET ORDER TO TAG cprogram
	APPEND BLANK
	REPLACE cprogram WITH 'msgbox'
	REPLACE mcode WITH ;
		"PARAMETERS cmsg,nbuttons,ctitle"+CHR(13);
		+"IF TYPE('cmsg')='L'"+CHR(13);
		+"	cmsg='This is a test message.'"+CHR(13);
		+"ENDIF"+CHR(13);
		+"IF TYPE('nbuttons')='L'"+CHR(13);
		+"	nbuttons=16"+CHR(13);
		+"ENDIF"+CHR(13);
		+"IF TYPE('ctitle')='L'"+CHR(13);
		+"	ctitle='IMPORTANT MESSAGE'"+CHR(13);
		+"ENDIF"+CHR(13);
		+"MESSAGEBOX(cmsg,nbuttons,ctitle)"+CHR(13)
	IF SEEK('msgbox','codefile','cprogram')
		*VFP7/VFP8 code:
		EXECSCRIPT(codefile.mcode,'This example uses the execscript command'+CHR(13)+'and requires VFP7 or above.',64,'codeFile example.')
		*VFP6 SP3 (added compile command) and below code:
		STRTOFILE(mcode, lcFileName )
		COMPILE (lcFileName)
		DO (lcFileName) WITH 'This example uses the compile command.'+CHR(13)+'and works in VFP6 SP3 and below',64,'codeFile example.'
	ELSE
		WAIT WINDOW "Could Not Find Program to Run." AT 22,35
	ENDIF
#ELSE
	SET SAFETY OFF
	SELE 0
	CREATE TABLE codefile (cprogram c(15), mcode m)
	INDEX ON cprogram TAG cprogram
	SET ORDER TO TAG cprogram
	APPEND BLANK
	REPLACE cprogram WITH 'waitbox'
	REPLACE mcode WITH ;
		"PARAMETERS cmsg,ntimeout"+CHR(13);
		+"IF TYPE('cmsg')='L'"+CHR(13);
		+"	cmsg='This is a test message.'"+CHR(13);
		+"ENDIF"+CHR(13);
		+"IF TYPE('ntimeout')='L'"+CHR(13);
		+"	ntimeout=5"+CHR(13);
		+"ENDIF"+CHR(13);
		+"mycode=' WAIT WINDOW '"+";"+CHR(13);
		+"+CHR(39)+cmsg+CHR(39)"+";"+CHR(13);
		+"+' TIMEOUT '";
		+"+ALLTRIM(STR(ntimeout))";
		+CHR(13);
		+"&mycode"
	IF SEEK('waitbox','codefile','cprogram')
		*
		IF !FILE(lcFileName)
			xfileh = FCREATE(lcFileName)
		ELSE
			xfileh = FOPEN(lcFileName,2)
		ENDIF
		IF xfileh=0
			WAIT WINDOW "Cannot create the program." NOWAIT
		ELSE
			=FCHSIZE(xfileh,0)
			xiniline=codefile.mcode
			=FPUTS(xfileh,xiniline)
			=FCLOSE(xfileh)
		ENDIF
		IF FILE(lcFileName)
			? lcFilename
			DO (lcFileName) WITH 'This is an example using the compile for FPD26.',10
		ENDIF
	ELSE
		WAIT WINDOW "Could Not Find Program to Run." AT 22,35
	ENDIF
#ENDIF
IF USED('codefile')
	USE IN codefile
ENDIF
IF FILE(lcFileName)
	DELETE FILE (lcFileName)
ENDIF
IF FILE(lcDelete)
	DELETE FILE (lcDelete)
ENDIF
RETURN

**************
>>Is there a strtofile equivalent in FPD26? I'd like to run the code below in FPD26 (see compile directives-only bottom portion is for FPD26) but it bombs out at the StrToFile portion of course:
>>
>Tracy;
>
>Here is both filetostring/stringtofile compatibles functions for 2.6:
>
>
>FUNCTION filetostring
>LPARAMETER lcdatafile                     && .txt (line sequential) file
>lndfh=FOPEN(lcdatafile)
>lcparameter=""
>IF  lndfh > 0
>    nsize =  FSEEK(lndfh, 0, 2)           && Move to EOF
>    IF  nsize <= 0
>    ELSE
>        = FSEEK(lndfh, 0, 0)
>        DO WHILE NOT FEOF(lndfh)
>            lcparameter=lcparameter+FREAD(lndfh,nsize)
>        ENDDO
>        *
>        cwcofc     = lcparameter
>    ENDIF
>    =FCLOSE(lndfh)
>ELSE
>    * Error opening data file
>    Wait window "File "+lcdatafile+" do not exists !!" nowait
>ENDIF
>RETURN lcparameter
>
>function stringtofile
>parameter mMystring, lcdatafile     && memo field, output file
>lndfh = fopen(lcdatafile)           && you can use fcreate instead of fopen
>if  lndfh > 0
>    memo_size = memlines(mMystring)
>    for i = 1 to memo_size
>        m.cLyne   = MLINE(mMystrring, i)
>        =fputs(lndfh, m.cLyne)      && depending on how your file is organized you can use fwrite
>    endfor
>    =FCLOSE(lndfh)
>else
>    Wait window "File "+lcdatafile+" do not exists !!" nowait
>endif
>return
>
>
>
>HTH
>
>
>Claudio
.·*´¨)
.·`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
Reply
Map
View

Click here to load this message in the networking platform