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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating tab delimited files from Clipper 2

Status
Not open for further replies.

fbizzell

Programmer
Jul 3, 2000
217
I have the need to create a tab delimited file of data from an Clipper (dbase III Plus) data file. The application that needs this text file to import data can not use a fixed field length text file or a space delimited text file. It must have one that is delimited by tabs.

Can this be done?
 
Thank you for that information.

Richard L. Hankins Jr.
Senior Programmer
Auction Services, Inc.
 
Elkari,

Please explain "Bumped for LAADO"

Frank
 
Frank,

Like in all forums, when a new message is added to a thread the thread is moved to the top of that particular forum. LAADO is another person who requested information about TAB delimited files. Instead of rewriting all that I did in this thread, I just 'bumped' it to the top so LAADO could find it easier. I hope this didn't cause a problem for anyone.[thumbsup]

Elkari
 
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 :=&quot;&quot;// 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 )

 
Here's the fix -

Old Code
nPos := at( chr( 9 ), cString ) // Check for a TAB
if ( nPos == 0 )
exit
endif
cData := substr( cString, 1, nPos - 1 )

Fix
nPos := at( chr( 9 ), cString ) // Check for a TAB
if ( nPos == 0 ) // No more TABs found
cData := cString
elseif
cData := substr( cString, 1, nPos - 1 )
endif

Let me know how it goes.[pc2]
 
Great! Fantastic! Thanks for the help. I had to change the elseif to an else and it worked like a charm.

I wish you would send me your address so I could send you a special gift from TEXAS! to help you celebrate the holidays!

Frank
 
OOPS...my bad. I already have a nice gift from Texas. It's a Texan's map of the USA magnet.[thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top