There're lots of text file types. To import a simple CSV file use this: APPEND FROM (thisform.txtInputFile.Value) TYPE CSV AS 1250
To import a TAB delimited text file use this: APPEND FROM (thisform.txtInputFile.Value) DELIMITED WITH TAB AS 1250
To import a custom character delimited text file, use this: cmd="APPEND FROM "+thisform.txtInputFile.Value+" DELIMITED WITH CHARACTER "+delchar+" AS 1250" &cmd
It all depends in what format the data is in. If it is a simple comma delimited file (CSV) or an SDF file (a flat file with no separators or delimiters), you create a table with the proper structure to receive the data then do an APPEND FROM.
Read the help file for APPEND FROM as it has many modifiers.
Using the modifiers (DELIMITED WITH and CHARACTER) you can also import data delimited with any character other than commas.
Being FoxPro, you know that anything can be done in many different ways.
There are other commands and fucntions to do this.
You can use FILETOSTR() to read a text file into memory You can use Low Level functions to read by bytes (FCREATE() / FOPEN() / FREAD() / FGETS(), etc.)
i dont think that the code below is what you really need but i though i give it to you anyway,actually you can find it in help too Public pathtemp pathtemp="c:\mydirectory\" ************** IF FILE('PREVIOUS.txt') && Does file exist gnErrFile = FOPEN(pathtemp+'PREVIOUS.txt',1) && If so, open read/write ELSE gnErrFile = FCREATE(pathtemp+'PREVIOUS.txt') && If not, create it ENDIF IF gnErrFile < 0 && Check for error opening file MESSAGEBOX("cant create file","ERROR",048) ENDIF =FCLOSE(gnErrFile) && Close file
Local gnFileHandle,nSize,cString gnFileHandle = FOPEN(pathtemp+'PREVIOUS.txt') * Seek to end of file to determine number of bytes in the file. nSize = FSEEK(gnFileHandle, 0, 2) && Move pointer to EOF IF nSize <= 0 * If file is empty, display an error message. WAIT WINDOW "This file is empty!" NOWAIT ELSE * If file is not empty, store the file's contents in memory * and display the text in the main Visual FoxPro window. = FSEEK(gnFileHandle, 0, 0) && Move pointer to BOF cString = FREAD(gnFileHandle, nSize) THISFORM.Ccombobox1.DisplayValue =cString ENDIF = FCLOSE(gnFileHandle) && Close the file
if you need to read specific values you could put a for loop in fread to read 1 character each time(nsize=1)and store them in variables.for example read until it founds a gap " "so you understand its a diffrent word ahead.
Load Data
cptscottie
There're lots of text file types. To import a simple CSV file use this:
APPEND FROM (thisform.txtInputFile.Value) TYPE CSV AS 1250
To import a TAB delimited text file use this:
APPEND FROM (thisform.txtInputFile.Value) DELIMITED WITH TAB AS 1250
To import a custom character delimited text file, use this:
cmd="APPEND FROM "+thisform.txtInputFile.Value+" DELIMITED WITH CHARACTER "+delchar+" AS 1250"
&cmd
Sussch
Jarron,
It all depends in what format the data is in. If it is a simple comma delimited file (CSV) or an SDF file (a flat file with no separators or delimiters), you create a table with the proper structure to receive the data then do an APPEND FROM.
Read the help file for APPEND FROM as it has many modifiers.
E.g.
USE MyNewTable
APPEND FROM MyTextFile.txt
See:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dv_foxhelp9/html/2cb5be90-2563-455d-bd3c-8a243aff5211.asp frame=true
Using the modifiers (DELIMITED WITH and CHARACTER) you can also import data delimited with any character other than commas.
Being FoxPro, you know that anything can be done in many different ways.
There are other commands and fucntions to do this.
You can use FILETOSTR() to read a text file into memory
You can use Low Level functions to read by bytes (FCREATE() / FOPEN() / FREAD() / FGETS(), etc.)
Many many ways to do accomplish the task.
HTH
fbalas
Teenprogrammer
Public pathtemp
pathtemp="c:\mydirectory\"
**************
IF FILE('PREVIOUS.txt') && Does file exist
gnErrFile = FOPEN(pathtemp+'PREVIOUS.txt',1) && If so, open read/write
ELSE
gnErrFile = FCREATE(pathtemp+'PREVIOUS.txt') && If not, create it
ENDIF
IF gnErrFile < 0 && Check for error opening file
MESSAGEBOX("cant create file","ERROR",048)
ENDIF
=FCLOSE(gnErrFile) && Close file
Local gnFileHandle,nSize,cString
gnFileHandle = FOPEN(pathtemp+'PREVIOUS.txt')
* Seek to end of file to determine number of bytes in the file.
nSize = FSEEK(gnFileHandle, 0, 2) && Move pointer to EOF
IF nSize <= 0
* If file is empty, display an error message.
WAIT WINDOW "This file is empty!" NOWAIT
ELSE
* If file is not empty, store the file's contents in memory
* and display the text in the main Visual FoxPro window.
= FSEEK(gnFileHandle, 0, 0) && Move pointer to BOF
cString = FREAD(gnFileHandle, nSize)
THISFORM.Ccombobox1.DisplayValue =cString
ENDIF
= FCLOSE(gnFileHandle) && Close the file
if you need to read specific values you could put a for loop in fread to read 1 character each time(nsize=1)and store them in variables.for example read until it founds a gap " "so you understand its a diffrent word ahead.
billaras,im a noob vfp programmer