• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

semi-colon seperated file to label printer.

I have a semi-colon seperated file list with the following format:

Product;Ordernr;Name;Address;Town;Postcode;Country
Product;Ordernr;Name;Adress;Town;Postcode;Country
Product;Ordernr;Name;Adress;Town;Postcode;Country

This list has to be printed out onto labels via LPT1.
as:
       Product Ordernr
       Name
       Address
       Town Postcode
       Country

The labels measure 2cm x 8cm, and on a endless role.
------------------------------------------------------

How can I code this in Turbo Pascal.?


0
thehaze
Asked:
thehaze
  • 17
  • 11
  • 8
  • +1
1 Solution
 
OkeyCommented:
First :
 Create a textfile with corect text structure.

Second :

 Now open it with WORD and create with its functions your labels automaticaly!
0
 
dbruntonCommented:
This part is easy

while not eof (Labels) do
 begin
   readln(Labels, string);

This part is not

   Now break the string up by doing a search for the ;
   this will give you each word
   The trouble is the printing
   You will need to know the commands to feed to the printer for fonts and positioning of the print head
   This is usually printer dependent
   You will need the printer manual which will give you the ESC commands to feed to the printer
 end;
0
 
OkeyCommented:
I bet you that you wont ever be able to do Direct IO from DOS-MODE to printer you use.
Especially TP has no solutions for Printing diffrent then with Fontsize 10 or wich is adjusted in DOS except you have a postscript or a special HP printer and you know how to store the Vektor-Fonts elsewise to answer the Question again you shouldn't look at PRNFLTR in ..\TP\BIN\
Yeah its possible but I bet you again that You wont listen to the answer!

It's very difficult to program! =  =  = = = == === ===@:-(>

Why reinvent the Wheel?


0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
thehazeAuthor Commented:
The printer is a normal matrix printer (24 dot).(endless paper).

Is it not possible to: Read file c:\text.asc
read each line,
Print as (evt to PRN file.?)
      Product Ordernr
      Name
      Address
      Town Postcode
      Country
<Line Break>
      Product Ordernr
      Name
      Address
      Town Postcode
      Country
<Line Break> etc etc
until end of file, then print to PRN.

The font type is not important, as the default printer font will be used.
0
 
dbruntonCommented:
That's possible if you don't care about font type and size.
Positioning is the problem.
If the labels are all under one another then it is a series of Writelns;

As you suggest

Writeln(Product Ordernr)
Writeln(Name)

Writeln;

You may strike the problem in that the writeln's won't line up evenly on each label.
0
 
thehazeAuthor Commented:
How would finished code look.? Taking into account:

Read from c:\text.txt

readln

write (label)

writeln
writeln

readln etc.
0
 
dbruntonCommented:
var
 labelstring : string;
 porder : string;
 name : string;
 address : string;
 tpcode : string;
 country : string;

while not eof (labelsfile) do
  begin
    readlnlLabelsfile, labelstring);
    porder := copy(labelstring, 1, pos(';', labelstring) - 1));
    labelstring := delete(labelstring, 1, pos(';', labelstring));
    name := copy(labelstring, 1, pos(';', labelstring) - 1));
    labelstring := delete(labelstring, 1, pos(';', labelstring));
    address := copy(labelstring, 1, pos(';', labelstring) - 1));
    labelstring := delete(labelstring, 1, pos(';', labelstring));

etc

  writeln(porder);
  writeln(name);
  writeln(address);

etc

  writeln:
  writeln;

end;

That's the meat of the code
0
 
VGRCommented:
PHOQUE

one hour of absence and it's already too late 8-)

well done dbrunton, you're "up and running" at the right time to catch THE Pascal question of the day ;-)
0
 
dbruntonCommented:
:-)

Well, where I live we catch the sun before anyone else.
0
 
VGRCommented:
the sun is down since 4 hours here :D
0
 
thehazeAuthor Commented:
What would the finished program look like.?
0
 
VGRCommented:
the code posted from dbrunton, plus "program" at the top, "begin" before the code and after the variables definitions, and "end." at the end.

This is a Pascal program. You're supposed to know the basic structure of a Pascal program...

PROGRAM programname(input,output);

USES
  (* uses *)

CONST
  (* constants *)

TYPE
  (* types *)

VAR
  (* variables *)

PROCEDURE/FUNCTION
  (* sub-routines *)

BEGIN
  (* code *)
END.

no ? :D
0
 
thehazeAuthor Commented:
What would the finished code for the program look like.?
0
 
dbruntonCommented:
Mistakes fixed.  Code tested.

program labelfrom;
uses printer;

var
labelsfile : text;
labelstring : string;
porder : string;
name : string;
address : string;
tpcode : string;
country : string;

begin
assign(labelsfile, 'TEXT');
reset(labelsfile);
while not eof (labelsfile) do
 begin
   readln(Labelsfile, labelstring);
   porder := copy(labelstring, 1, pos(';', labelstring) - 1);
   delete(labelstring, 1, pos(';', labelstring));
   name := copy(labelstring, 1, pos(';', labelstring) - 1);
   delete(labelstring, 1, pos(';', labelstring));
   address := copy(labelstring, 1, pos(';', labelstring) - 1);
   delete(labelstring, 1, pos(';', labelstring));
   tpcode := copy(labelstring, 1, pos(';', labelstring) - 1);
   delete(labelstring, 1, pos(';', labelstring));
   country := labelstring;
   writeln(lst, porder);
   writeln(lst, name);
   writeln(lst, address);
   writeln(lst, tpcode);
   writeln(lst, country);
{ for debugging purposes   readln; }
   writeln(lst);
end;
close(labelsfile);
end.
0
 
thehazeAuthor Commented:
Doesn't the 'lst' in 'writeln(lst);' have to be declared under VAR. I don't get any output.?
0
 
VGRCommented:
either do declare
var lst : text;

and in code :
assign(lst,'PRN:');
rewrite(lst);

or declare Program(InPut,'PRN:');
and use just WriteLn('yourstuff');
0
 
thehazeAuthor Commented:
Thanks VGR, that helped. Is it possible to print the 'address' and 'tpcode' on the same line.
0
 
VGRCommented:
of course, but I think you should experiment a bit more with Turbo-Pascal before trying to do real work 8-)

  writeln(lst, address,' ',tpcode);

here separated by a (white) space, but do as you wish (semi-colon, colon, dash, etc) this is just outputting strings to the output (= stdout if you know C-Style)

the force of pascal is in its ability to use statements like :
Program('KBD:','PRN:');
0
 
thehazeAuthor Commented:
I've adjusted the code so that it can be used on a order printer. Everything prints out fine, for example:
 
Melamin_Melamin  Hyl-1
759.5 x 330 x 16
Ordernr_123456  Week 23
 
2 Melamin_Melamin  Hyl-1
759.5 x 530 x 16

except the final line, which is left blank. Am I missing something.?

My final code looks like this..

program labelfrom;
uses printer;

var
labelsfile : text;
lst: text;
labelstring : string;
POS_1 : string;
POS_2 : string;
POS_3 : string;
POS_4 : string;
POS_5 : string;
POS_6 : string;
POS_7 : string;
POS_8 : string;
POS_9 : string;
POS_10 : string;

begin
assign(labelsfile,'List.asc');
assign(lst,'labtxt.txt');
rewrite(lst);
reset(labelsfile);
while not eof (labelsfile) do
begin
  readln(Labelsfile, labelstring);

 {  Number }
  POS_1 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{  Material }
  POS_2 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{  Element }
  POS_3 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{  Width }
  POS_4 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{  Height }
  POS_5 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{  Thickness }
  POS_6 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{  Turnable }
  POS_7 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{  Ordernr }
  POS_8 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
(Week)
  POS_9 := copy(labelstring, 1, pos(';', labelstring) - 1);
  delete(labelstring, 1, pos(';', labelstring));
{}
  POS_10 := labelstring;


  writeln(lst, POS_1 + '' + POS_2 + '' + POS_3);
  writeln(lst, POS_4 +' '+'x'+' '+ POS_5 +' '+'x'+' '+POS_6);
  writeln(lst, 'Ordernr'+'_'+POS_8 +' '+' '+'Week'+' '+ POS_10);

{ for debugging purposes   readln; }
  writeln(lst);
end;
close(labelsfile);
end.


 
0
 
VGRCommented:
no you don't miss anything. The final line is indeed empty :
writeln(lst);
0
 
VGRCommented:
given the simplicity of this program, if ever there a line missing in the output, check the input data 8-))
0
 
thehazeAuthor Commented:
It does not read in the last 2 fields of the list file, on the final line.

Input -> Listfile
3; Melamin_Melamin ; Hyl-1 ;759.5;330;16; Y ;123456;23
2; Melamin_Melamin ; Hyl-1 ;759.5;530;16; Y ;123456;23
2; Melamin_Melamin ; Hyl-1 ;959.5;530;16; Y ;123456;23

Output
-------
Melamin_Melamin  Hyl-1
759.5 x 330 x 16
Ordernr_123456  Week 23

2 Melamin_Melamin  Hyl-1
759.5 x 530 x 16

--------
It does not process the final ';123456;23'
which should read as  Ordernr_123456  Week 23.

 
0
 
VGRCommented:
leave an empty line at the end of the source file
if you prefer, do ENTER at the end of the last line :D
0
 
thehazeAuthor Commented:
Why doesn't it read the last part of the final line of input.?
0
 
thehazeAuthor Commented:
If I  write
writeln(lst,POS_1,POS_2,POS_3,POS_4,POS_5,POS_6,POS_7,POS_8,POS_9,POS_10);

Then on outputting the final 3 lines it produces
2 Melamin_Melamin  Hyl-1 759.528016 Y 12345623  
3 Melamin_Melamin  Hyl-1 759.533016 Y 12345623  
2 Melamin_Mel  
 
with a part of the final line missing.

There must be something amiss with the ending of the program.                    
0
 
dbruntonCommented:
Try doing some debugging

add a new variable

var
  copystr : string;

Then

after this line

readln(Labelsfile, labelstring);

copystr := labelstring;

And change these to


writeln(copystr);
writeln;
writeln(POS_1 + '' + POS_2 + '' + POS_3);
writeln(POS_4 +' '+'x'+' '+ POS_5 +' '+'x'+' '+POS_6);
writeln('Ordernr'+'_'+POS_8 +' '+' '+'Week'+' '+ POS_10);

and see if that works.




0
 
VGRCommented:
it's either a problem in the file on the last line (hence the crlf i asked you to put there)
-or an output problem : do a flush; before the final end.
0
 
thehazeAuthor Commented:
How do I code a 'crlf'. Can I use flush on text files.?
0
 
thehazeAuthor Commented:
How do I code a 'crlf'. Can I use flush on text files.?
0
 
VGRCommented:
you have access to the source file being processed, no ?
Then add a CARRIAGE RETURN (or RETURN) at the end of the last line.

Then see if it changes anything.

It's weird
0
 
VGRCommented:
you have access to the source file being processed, no ?
Then add a CARRIAGE RETURN (or RETURN) at the end of the last line.

Then see if it changes anything.

It's weird
0
 
thehazeAuthor Commented:
No, I don't have access to the make up of the source files. So all data manipulation must take place from within the TP prog.
0
 
thehazeAuthor Commented:
I tried dbruntons suggestion with the copystr, but it gave no output at all. I've tried debugging it, but there is no apparent fault.

Input is:
1; Melamin_Melamin ; Hyl-1 ;159.5;330;16; Y;123456;23
2; Melamin_Melamin ; Hyl-1 ;259.5;530;16; Y;123456;23  
2; Melamin_Melamin ; Hyl-1 ;359.5;132;16; Y;123456;23
4; Melamin_Melamin ; Hyl-1 ;359.5;150;16; Y;123456;23
4; Melamin_Melamin ; Hyl-1 ;359.5;280;16; Y;123456;23
-------------------------------
Program is:

program labelfrom;
uses printer;

var
labelsfile : text;
lst: text;
labelstring : string;
POS_1 : string;
POS_2 : string;
POS_3 : string;
POS_4 : string;
POS_5 : string;
POS_6 : string;
POS_7 : string;
POS_8 : string;
POS_9 : string;
POS_10 : string;
copystr : string;


begin
assign(labelsfile,'List.asc');
assign(lst,'labtxt.txt');
rewrite(lst);
reset(labelsfile);
while not eof (labelsfile) do
begin
 readln(Labelsfile, labelstring);
 copystr := labelstring;

{  Number }
 POS_1 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{  Material }
 POS_2 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{  Element }
 POS_3 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{  Width }
 POS_4 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{  Height }
 POS_5 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{  Thickness }
 POS_6 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{  Turnable }
 POS_7 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{  Ordernr }
 POS_8 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
 POS_9 := copy(labelstring, 1, pos(';', labelstring) - 1);
 delete(labelstring, 1, pos(';', labelstring));
{}
 POS_10 := labelstring;

{writeln(copystr);
writeln;
writeln(POS_1 + '' + POS_2 + '' + POS_3);
writeln(POS_4 +' '+'x'+' '+ POS_5 +' '+'x'+' '+POS_6);
writeln('Ordernr'+'_'+POS_8 +' '+' '+'Week'+' '+ POS_10);}

{This code gives a result except for the last line}
writeln(lst, POS_1 + '' + POS_2 + '' + POS_3);
writeln(lst, POS_4 +' '+'x'+' '+ POS_5 +' '+'x'+' '+POS_6);
writeln(lst, 'Ordernr'+'_'+POS_8 +' '+' '+'Week'+' '+ POS_10);

{ for debugging purposes   readln; }
 writeln(lst);
end;
close(labelsfile);
end.
---------------------------
 
Suggestions please.
0
 
thehazeAuthor Commented:
When debugging I get the error message:
File not found in step:
 
'reset(labelsfile);'

Even though the code can be compiled without error(?).

Could it be a stack / mem error.?
0
 
dbruntonCommented:
At end of file you have these three lines


end;
close(labelsfile);
end.

Try the following

end;
close(labelsfile);
writeln(lst, '');writeln(lst, '');
{   flush(lst);   Uncomment this line and try it if this doesn't work  }
close(lst);     { It's an open file close it }
0
 
thehazeAuthor Commented:
This code helps. It now prints all the lines of the input file, except on the last line where it types out all the chars that I have in ' '.

Melamin_Melamin  Hyl-1
759.5 x 330 x 16
Ordernr_123456  Week 23
 
 x  x  
Ordernr_  Week  

0
 
dbruntonCommented:
Which helps?

Make sure it's writeln(lst, '    ');    So you print spaces.
0
 
OkeyCommented:
It's clearly the Flush because of using File redirection to printer!
That's why TP so easy assigns the printer like a file,
because it uses DOS-Int $21 FILEhandling routines, which include the file redirection ability over special handles!

Man what all has happand yesterday night and today before midday?
0
 
thehazeAuthor Commented:
I get the same result without the flush.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 17
  • 11
  • 8
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now