Board index » delphi » Exporting data to a text file?

Exporting data to a text file?

Hi,
     i'm attempting to write a program to export data to text files
which can be picked up by our host system. I don't need to do anything
special with the data but i must ensure that if a field is 10 chars in
length and only contains data 5 chars in length that the field is padded
when written to the file.
I reckon that there must be a straight forward way of achieving this
(e.g. select required_fields into filename) but as of yet i don't know
what this is. Any help with this would be appreciated.
Thanks in advance,
Dermot O'Loughlin.
 

Re:Exporting data to a text file?


Sounds like you  need to use the format function.  Use a format like
%-10.10s, eg

writeln( f,  format('%-10.10s',s) );

Hope this helps

Jim Birch

Quote
D O'Loughlin wrote:
> Hi,
>      i'm attempting to write a program to export data to text files
> which can be picked up by our host system. I don't need to do anything
> special with the data but i must ensure that if a field is 10 chars in
> length and only contains data 5 chars in length that the field is padded
> when written to the file.
> I reckon that there must be a straight forward way of achieving this
> (e.g. select required_fields into filename) but as of yet i don't know
> what this is. Any help with this would be appreciated.
> Thanks in advance,
> Dermot O'Loughlin.

Re:Exporting data to a text file?


Thanks Jim,
                   but i'm more interested in knowing if there is a simple way
just to select the data i want and output it to a text file without having to
concern myself with formatting.
Dermot.
Quote
Jim Birch wrote:
> Sounds like you  need to use the format function.  Use a format like
> %-10.10s, eg

> writeln( f,  format('%-10.10s',s) );

> Hope this helps

> Jim Birch

> D O'Loughlin wrote:

> > Hi,
> >      i'm attempting to write a program to export data to text files
> > which can be picked up by our host system. I don't need to do anything
> > special with the data but i must ensure that if a field is 10 chars in
> > length and only contains data 5 chars in length that the field is padded
> > when written to the file.
> > I reckon that there must be a straight forward way of achieving this
> > (e.g. select required_fields into filename) but as of yet i don't know
> > what this is. Any help with this would be appreciated.
> > Thanks in advance,
> > Dermot O'Loughlin.

Re:Exporting data to a text file?


Quote
>     i'm attempting to write a program to export data to text files
>which can be picked up by our host system. I don't need to do anything
>special with the data but i must ensure that if a field is 10 chars in
>length and only contains data 5 chars in length that the field is padded
>when written to the file.

Is your source data in a table (I'm assuming...)? If so, BatchMove-ing it to
a TableType "ttAscii" would work:

<untested>
with TTable.create(nil) do
try
  Databasename := SourceTab.Databasename;
  Tablename := 'Export.txt';
  Tabletype := ttAscii;
  FieldDefs := SourceTab.FieldDefs;
  CreateTable;
  Open;
  BatchMove(SourceTab, batAppend);
finally
  Free;
end;

--
David Reed
Diamond Software Group
Oasis Rep Software, Inc
www.diamondsg.com
www.oasisrep.com

Re:Exporting data to a text file?


Thanks David,
                     seems like that's the way to achieve what i want to do.
Dermot.
Quote
David Reed wrote:
> >     i'm attempting to write a program to export data to text files
> >which can be picked up by our host system. I don't need to do anything
> >special with the data but i must ensure that if a field is 10 chars in
> >length and only contains data 5 chars in length that the field is padded
> >when written to the file.

> Is your source data in a table (I'm assuming...)? If so, BatchMove-ing it to
> a TableType "ttAscii" would work:

> <untested>
> with TTable.create(nil) do
> try
>   Databasename := SourceTab.Databasename;
>   Tablename := 'Export.txt';
>   Tabletype := ttAscii;
>   FieldDefs := SourceTab.FieldDefs;
>   CreateTable;
>   Open;
>   BatchMove(SourceTab, batAppend);
> finally
>   Free;
> end;

> --
> David Reed
> Diamond Software Group
> Oasis Rep Software, Inc
> www.diamondsg.com
> www.oasisrep.com

Re:Exporting data to a text file?


Did BatchMove pad or added spaces to string fields with less than 10
characters in length?

Edgar D. Jordan
sp...@k-net.edu

Quote
D O'Loughlin wrote in message <376E4FD1.5EDEE...@portablesolutions.com>...
>Thanks David,
>                     seems like that's the way to achieve what i want to
do.
>Dermot.

>David Reed wrote:

>> >     i'm attempting to write a program to export data to text files
>> >which can be picked up by our host system. I don't need to do anything
>> >special with the data but i must ensure that if a field is 10 chars in
>> >length and only contains data 5 chars in length that the field is padded
>> >when written to the file.

>> Is your source data in a table (I'm assuming...)? If so, BatchMove-ing it
to
>> a TableType "ttAscii" would work:

>> <untested>
>> with TTable.create(nil) do
>> try
>>   Databasename := SourceTab.Databasename;
>>   Tablename := 'Export.txt';
>>   Tabletype := ttAscii;
>>   FieldDefs := SourceTab.FieldDefs;
>>   CreateTable;
>>   Open;
>>   BatchMove(SourceTab, batAppend);
>> finally
>>   Free;
>> end;

>> --
>> David Reed
>> Diamond Software Group
>> Oasis Rep Software, Inc
>> www.diamondsg.com
>> www.oasisrep.com

Re:Exporting data to a text file?


Use the TBatchMove component in conjunction with the BDE ASCII driver. The
best documentation for the BDE ASCII driver is the file ASCIIDRV.TXT in the
Delphi 1 Doc directory on your Delphi CD. Second best is the on-line help.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to email questions. To contact me
 for any other reason remove nospam from my address.)

Other Threads