Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
EOF marker in csv, text files
Message
From
13/08/2001 08:44:51
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Miscellaneous
Thread ID:
00542920
Message ID:
00542944
Views:
23
>In VFP 6 it can be done in a few lines of code
lcData = Filetostr("Myfile.csv")
>IF ASC(RIGHT(lcData,1)) = 26    && make sure that its CTRL+Z
>  = Strtofile(LEFT(lcData, LEN(lcData)-1), "Myfile.csv")
>ENDIF
Sergey,

Instead of posting or using two different versions of a program, one with, one without, FileToStr() or StrToFile(), I suggest to always use FileToStr() and StrToFile(), even in older versions of VFP. These functions are so extremely handy that it is worthwhile to define them as UDFs in older versions - in fact, I wonder why I didn't create something similar before the advent of VFP6!

Actually, I created the following functions, because I needed to adapt some VFP6 code to VFP3. They seem to work fine. Some adjustments would be required for FoxPro 2.x (null values, parameter syntax).
**********************************************************************
FUNCTION StrToFile(tcExpression, tcFileName, tlAdditive)
* By Hilmar Zonneveld. May be distributed and used freely.
* Duplicate StrToFile() function, available in VFP6, for older versions.
local lnFile
if tlAdditive
	lnFile = fopen(tcFileName, 1)
	if lnFile < 1
		tlAdditive = .F.	&& go on creating file
	endif
	fseek(lnFile, 0, 2)	&& go to end of file
endif
if not tlAdditive	&& either invoked without parameter "tlAdditive" = .T., or file does not exist
	lnFile = fcreate(tcFileName)
	if lnFile < 1
		Error 102, tcFileName	&& Cannot create file
		return
	endif
endif
fwrite(lnFile, tcExpression, 1e9)
fclose(lnFile)


**********************************************************************
FUNCTION FileToStr(tcFileName)
* By Hilmar Zonneveld. May be distributed and used freely.
* Duplicate FileToStr() function, available in VFP6, for older versions.
local lcReturnValue, lnFile
lnFile = fopen(tcFileName)
if lnFile < 0
	Error 101, tcFileName	&& Cannot open file
	lcReturnValue = ""
	lcReturnValue = .NULL.
	return lcReturnValue
endif
lcReturnValue = ""
do while not feof(lnFile)
	* Upper limit for fread is somewhere between 1e7 and 2e7.
	lcReturnValue = lcReturnValue + fread(lnFile, 1e7)
enddo
fclose(lnFile)
return lcReturnValue
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform