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

exporting to a text file without separator

Status
Not open for further replies.

cobweb

IS-IT--Management
May 5, 2002
95
GB
Hi there:

I have a problem where I am trying to export to a text file but where the separator should not exist.
The delimiter is pipe.
So my code is:
exportASCIIVar("test.db","test.txt",,"|",True,False)
which is rejected because an identifier is expected for the separator.
But what should it be when I do not want one?

Thanks!
 
cobweb,

It appears that you cannot use exportASCIIVar() to specify a blank separator. I tried a few variants and it seems that the original developer added code to the underlying routine that detects that condition and, if detected, default to using a comma.

IIRC, the UI calls this, so it make sense from an engineering standpoint. It's frustrating from a user standpoint, but don't forget that you can roll your own export routine with a TCursor and liberal use of the TextStream class.

It seems like a lot of work, but it goes quickly. For an example, please see which shows how to use use this technique to export memos and BLOB's.

Your need can be met with a simplified version of that code. You won't, for example, need the fixup routine.

Hope this helps...

-- Lance
 
cobweb,

I agree with footpad's conclustion, here is a simple example of who to acheive the result with the textstream

Code:
method pushButton(var eventInfo Event)
var
	tc tcursor
	ts textStream
	ar dynarray[] anytype
	el, seperator anytype
endvar

seperator = "|"

if not tc.open("bulktmp") then
	errorshow()
endif
ts.open("test.txt", "nw")

scan tc:
	tc.copyToArray(ar)
	foreach el in ar
		ts.writestring(seperator+ar[el]+seperator)
	endforeach 
   ts.writeLine()
endscan
endMethod

Hope this helps
Perrin
 
In retrospect "seperator" probably wasn't the best name for the variable because that's what you are trying to get rid of, what can I say it's Monday. The code should work just the same.....
 
Thank you very much again, both of you!
The principle is fine and works really well...however the layout of my table does not correspond to the layout of the text file that is written from it!
I cannot see any particular pattern to this.
The table comprises 132 fields. The first 4 are primary key. They are a mix of data types but no memo or BLOB.
Reading my manual suggests I may need to use textstream to write each field in the correct order rather than use an array...do you agree or is there another way?

Thanks again for what you have done!
 
cobweb,

I used the array because it's a simple generic way of doing the task without having to worry about the number of fields or field names. In your case you may have to manually write the fields in the correct order.

Another option is to run a query and have it change the field order of the answer table to the required order, then write the text file directly from the answer table using the array method. You may already be running a query to extract the data you need, if so this would be a simple solution. You can easily change the field order in a query using "Query Properties" or in ObjectPal using "FIELDORDER".

The more I think of it the more I like the Query option, mainly for the ease of changing around the field order, with 132 fields you may end up with a major headache before you get all the fields named and placed correctly.


Perrin


 
Thanks again, guys.
My query still did not put things in the right order but it only took a few minutes to write out the textstream.

Another job done - thanks to you!
 
Hi there guys...job not quite done!

When I manually export the table the dates return as 28/02/04 (this is the UK, you know!)
Exporting via textstream returns dates as 28/02/2004
.....and the import to the accounts system fails.

Are you aware of anything like this; and how to resolve it?
Paradox 9, by the way.
Also the dates may be different for each record.

Thanks again !
 
Ahh, it's always something. I'm guessing that the export uses the windows date format and the textstream just writes the raw data. This should be easy to fix using format("D10",data), be aware that this will put in 00/00/0000 if the field is blank so you will have to code around that.

something like
iif(tc.dateFld.isblank(),"",format("D10",tc.dateFld))

I'm not sure why the query didn't rearange the fields for you, it worked for me, just as well though now that you have to add the format.

Perrin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top