I am having problem with the program that reads a tab delimted file into a Clipper database. It is not picking up the last column in the tab delimited file. I thought it was working great because I didn't need that last column but now I do. Here is the code. ELKARI, can you fix this so the last column is also added to the database?
function TabIn
local i, cData, cString, nCount, nFieldCount, nFileSize, nInHandle
nInHandle := fopen( 'newcomp.txt' )
nFileSize := fseek( nInHandle, 0, 2 ) // Find file size
fseek( nInHandle, 0, 0 )
select NEWCOMP2//this is my dbf file
go top
nFieldCount := fcount()
**-- Loop until end of file
do while ( fseek( nInHandle, 0, 1 ) < nFileSize )
cString := readln( nInHandle )
nCount := 1
**-- There's data to add
if ( len( cString ) > 0 )
append blank
rlock()
endif
**-- Loop to parse each line
do while ( len( cString ) > 0 )
nPos := at( chr( 9 ), cString ) // Check for a TAB
if ( nPos == 0 )
exit
endif
cData := substr( cString, 1, nPos - 1 )
**-- Convert data to proper field format
if ( valtype( fieldget( nCount ) ) == 'M' ) // Memo Field
elseif ( valtype( fieldget( nCount ) ) == 'D' ) // Date Field
cData := CTOD( cData )
elseif ( valtype( fieldget( nCount ) ) == 'N' ) // Numeric Field
cData := val( cData )
elseif ( valtype( fieldget( nCount ) ) == 'L' ) // Logical Field
cData := iif( cData == '1', .t., .f. )
endif
fieldput( nCount, cData )
nCount++
**-- Check for too much data on a line
if ( nCount > nFieldCount )
exit
endif
**-- Reposition string
cString := substr( cString, nPos + 1 )
enddo
unlock
enddo
fclose( nInHandle )
close
return ( .t. )
function readln ( nHandle )
local cString, nPos, ;
cReturn :=""// NULL
do while (.t.) //was TRUE
if ( len( ( cString := freadstr( nHandle, 256 ) ) ) == 0 )
exit
elseif ( ( nPos := at( chr( 13 ) + chr( 10 ), cString ) ) > 0 )
cReturn += left( cString, nPos - 1 )
if ( nPos < len( cString ) - 1 )
fseek( nHandle, - ( len( cString ) - nPos - 1 ), 1 )
endif
exit
endif
cReturn += cString
enddo
return ( cReturn )