?
Solved

semi-colon seperated file to label printer.

Posted on 2003-04-01
39
Medium Priority
?
456 Views
Last Modified: 2011-09-20
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
Comment
Question by:thehaze
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 11
  • 8
  • +1
39 Comments
 
LVL 1

Expert Comment

by:Okey
ID: 8247935
First :
 Create a textfile with corect text structure.

Second :

 Now open it with WORD and create with its functions your labels automaticaly!
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 8247962
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
 
LVL 1

Expert Comment

by:Okey
ID: 8248019
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:thehaze
ID: 8248033
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
 
LVL 49

Expert Comment

by:dbrunton
ID: 8248224
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
 

Author Comment

by:thehaze
ID: 8248317
How would finished code look.? Taking into account:

Read from c:\text.txt

readln

write (label)

writeln
writeln

readln etc.
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 8248441
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
 
LVL 15

Expert Comment

by:VGR
ID: 8248820
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
 
LVL 49

Expert Comment

by:dbrunton
ID: 8248851
:-)

Well, where I live we catch the sun before anyone else.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8248930
the sun is down since 4 hours here :D
0
 

Author Comment

by:thehaze
ID: 8251182
What would the finished program look like.?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8251740
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
 

Author Comment

by:thehaze
ID: 8251860
What would the finished code for the program look like.?
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 8251874
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
 

Author Comment

by:thehaze
ID: 8252391
Doesn't the 'lst' in 'writeln(lst);' have to be declared under VAR. I don't get any output.?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8252440
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
 

Author Comment

by:thehaze
ID: 8252551
Thanks VGR, that helped. Is it possible to print the 'address' and 'tpcode' on the same line.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8252583
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
 

Author Comment

by:thehaze
ID: 8253130
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
 
LVL 15

Expert Comment

by:VGR
ID: 8253157
no you don't miss anything. The final line is indeed empty :
writeln(lst);
0
 
LVL 15

Expert Comment

by:VGR
ID: 8253171
given the simplicity of this program, if ever there a line missing in the output, check the input data 8-))
0
 

Author Comment

by:thehaze
ID: 8253224
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
 
LVL 15

Expert Comment

by:VGR
ID: 8253261
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
 

Author Comment

by:thehaze
ID: 8253385
Why doesn't it read the last part of the final line of input.?
0
 

Author Comment

by:thehaze
ID: 8253435
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
 
LVL 49

Expert Comment

by:dbrunton
ID: 8254112
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
 
LVL 15

Expert Comment

by:VGR
ID: 8254558
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
 

Author Comment

by:thehaze
ID: 8254968
How do I code a 'crlf'. Can I use flush on text files.?
0
 

Author Comment

by:thehaze
ID: 8254969
How do I code a 'crlf'. Can I use flush on text files.?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8255085
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
 
LVL 15

Expert Comment

by:VGR
ID: 8255100
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
 

Author Comment

by:thehaze
ID: 8255408
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
 

Author Comment

by:thehaze
ID: 8255655
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
 

Author Comment

by:thehaze
ID: 8255940
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
 
LVL 49

Expert Comment

by:dbrunton
ID: 8260154
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
 

Author Comment

by:thehaze
ID: 8260225
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
 
LVL 49

Accepted Solution

by:
dbrunton earned 300 total points
ID: 8260291
Which helps?

Make sure it's writeln(lst, '    ');    So you print spaces.
0
 
LVL 1

Expert Comment

by:Okey
ID: 8260685
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
 

Author Comment

by:thehaze
ID: 8260853
I get the same result without the flush.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question