Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using FEOF due to CRC checker

Status
Not open for further replies.

MForrest

Programmer
Jun 9, 2003
85
0
0
GB
Hi all, I am using the following code to import data from a csv file to my table:

* NOTE: all this function does is grab all the data between quotes, ie. the fields.

c = ""

do while c <> '"' and !feof(f_hand)
c = fread( f_hand, 1)
enddo

temp_str = ""
c = ""

do while c <> '"' and !feof(f_hand)
c = fread( f_hand, 1)
if c <> '"' then
temp_str = temp_str + c
endif
enddo

If the csv file does not contain enough data to populate all the fields of my table then it reads each of the 4 characters which make up the crc checker (at the end of my csv file) to populate any remaining fields in my table until the feof function is reached. I did not implement the crc checker but can see that each csv file created contains 4 characters which makes up the crc value. I was thinking therefore if I could add a check along side the feof function to only read from the file handle if we have not reached the 4th character to the right of the csv file. Do you think this is a sure and safe way of controlling this situation and if so does anyone know i can control this???
 
MForrest

If your data is consistent, why not just use the APPEND FROM. I use this technique many times a day and never had a problem.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks for the reply Mike, my data is not consistent, I have data coming in from two versions of an application the first version having fewer data fields.

Gaining control of the file pointer in my file handle and tracking what version my import data is from now gives me the control to read the data correctly, thus not even looking at the crc checker at the end of the csvb file. It may seem like a complex fix to the problem but its working after a lot of messing about.

What happens when I read in from the csv is one chunk of data is read into a temporary array and then gathered to my main table the remaining data is read into another temporary array and gathered into one of many linked tables. The way in which this import facility has been coded relies upon the data fields being the same between the data to import and the tables to be read into, lucklily I have a version flag saved to this data so using that and using the following code i can dimension my array to read in only the data required for my table and then move the file pointer in the file handle back to the specific point in the file handle where the next chunk of data should start from. The other programmer who coded the import facility has not put any flag between where one tables info starts and ends you see.

* first batch of data to be gathered from file to import

if version == "V1"
* removing elements of data from 54 to 47 as the table controling how much data is read from the file_handle has extra fields than the data file to import
DIMENSION ret_array(47)
endif

* second batch of data to be gathered from file to import
* moving file pointer back x characters (7 fields worth of data) which was read into my first temporary array

if version_no == "V1"
do case
case sketch_type == "Common Crossings"
struct_size = 94
fseek(f_handle, -210, 1)
case sketch_type == "Obtuse Crossings"
struct_size = 80
fseek(f_handle, -151, 1)
endcase
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top