Breaking Description

I want to break the description while printing it on the invoice. The length of my item description is 150 characters. But when I am printing it i want to print it into multiple rows. And each row can print only 30 chars max. And also while printing the description I want to wrap around as per word. i.e. I dont want to cut the word in between. Does anybody has any solution on this. Thx in advance for ur valuble suggestions/solutions. Jagjeet

Maybee not the shortest code, and it needs expansion for what you are trying to do but it could go something like this : v_HelpString1 := COPYSTR(v_DescriptionCut[1],30,1); v_HelpString2 := COPYSTR(v_DescriptionCut[2],1,1); IF (v_HelpString1 <> ’ ') AND (v_HelpString2 <> ’ ') THEN BEGIN MESSAGE(‘Case occured with last string of [1] being : %1 and the first char of string [2] being : %2’, v_HelpString1,v_HelpString2); FOR v_I := 29 DOWNTO 1 DO BEGIN v_Helpstring3 := COPYSTR(v_DescriptionCut[1], v_I, 1); IF v_Helpstring3 = ’ ’ THEN BEGIN v_DescriptionCut[1] := COPYSTR(v_Description,1,v_I); v_DescriptionCut[2] := COPYSTR(v_Description,v_I+1,30); v_DescriptionCut[3] := COPYSTR(v_Description,v_I+1+30,30); v_DescriptionCut[4] := COPYSTR(v_Description,v_I+1+60,30); v_DescriptionCut[5] := COPYSTR(v_Description,v_I+1+90,30); v_DescriptionCut[6] := COPYSTR(v_Description,v_I+1+120,30); EXIT; END; END; END; No, the code is not finished, it only does one proper cut of the text. Furthermore it would require testing if there are descriptions with very large texts and so on … some work to do here.

hi coppens thx for the solutions. But I think this will also cut down word in between. Which I dont want. For example : If I have description say “Microsoft SQL Server 2000 Administration Companion” And I want that maximum description can be printed on line is of 30 characters. but with ur code I think the description will be printed as “Microsoft SQL Server 2000 Admi” and on next line it will print the rest. Which I dont want. I want the description to be printed as “Microsoft SQL Server 2000” and on the second line it should print “Administration Companion” i.e. I dont want to cut the word in between. Jagjeet

Hi Jagjeet It can be done but you have to modify the invoice print report substantially. 1) Add additional sections to the report one with the Description text box expanded to two rows, another with it expanded to three rows etc. Set the property MultiLine to Yes. The source expressions for the additional text boxes will be new global variables smalldescr, mediumdescr and largedescr. 2) In the OnAfterGetrecord of the line dataitem you need to decide which section of the report to use. eg IF ((STRLEN(Rec.Description) > 40) AND (STRLEN(Rec.Description) <= 80)) THEN BEGIN SmallDescr := Rec.Description; UsesmallDescr := TRUE; END; IF ((STRLEN(Rec.Description) > 81) AND (STRLEN(Rec.Description) <= 120)) THEN BEGIN MediumDescr := Rec.Description; UseMediumDescr := TRUE; END; IF STRLEN(Rec.Description) > 120 THEN BEGIN LargeDescr := Rec.Description; UseLargeDescr := TRUE; END; 3) You need to modify OnPreSection of each line section. Eg Currreport.showoutput(UseMediumDescr) 4) Finally you must take control of the printing of transfer headings etc by keeping a linecount that takes account of the section you printed and throws a new page when appropriate. This is not exact, you cannot predict exactly where a line of description will break but if you do it this way, no words will be broken.

This is the way I use to solve this one: Vars: Description, Text, 100 ArrayVar, Text, 25 ArrayCounter, Integer LastBlankPosition, Integer i, Integer :: Code: Description := DELCHR(Description,’<>’); ArrayCounter := 0; WHILE Description <> ‘’ DO BEGIN ArrayCounter += 1; ArrayVar[ArrayCounter] := COPYSTR(Description,1,MAXSTRLEN(ArrayVar[1])); IF Description = ArrayVar[ArrayCounter] THEN Description := ‘’ ELSE IF (COPYSTR(Description,MAXSTRLEN(ArrayVar[1]),1) <> ’ ‘) AND (COPYSTR(Description,MAXSTRLEN(ArrayVar[1]) + 1,1) <> ’ ‘) THEN BEGIN LastBlankPosition := 0; i := 1; WHILE i > 0 DO BEGIN i := STRPOS(COPYSTR(ArrayVar[ArrayCounter],LastBlankPosition + 1),’ ‘); IF i > 1 THEN BEGIN LastBlankPosition += i; END; END; IF LastBlankPosition = 0 THEN ERROR(‘Cannot split line.’); ArrayVar[ArrayCounter] := COPYSTR(ArrayVar[ArrayCounter],1,LastBlankPosition - 1); end; ArrayVar[ArrayCounter] := DELCHR(ArrayVar[ArrayCounter],’<>’); Description := DELCHR(COPYSTR(Description,STRLEN(ArrayVar[ArrayCounter]) + 1),’<>’); END; ::

Eureka !!! :)) Hey guys I have done the breaking of Description by word not by characters. I am pasting the code over here. Hope this will be helpful to some of our friends in Navision World. What the following code will do is cut the description with max string length of 30 characters and put them in a temp desc table. I have done slite change bcos i hv to print the same in the Sales invoice report. In the Sales Invoice report I have added a new Dataitem as Integed and named it as Description under SalesInvoice line. Variables : Name DataType Subtype Length str Text 250 ctr Integer oStr Text 250 nStr Text 30 sStr Text 30 Found Boolean IntTable Record Integer i Integer pos Integer Read Integer rectable Record TempDescTable Code str := ‘Microsoft SQL Server 2000 Administration Companion’; ctr := ROUND(STRLEN(str)/30,1,’>’); nStr := COPYSTR(str,1,30); i := 1; WHILE i <= ctr DO BEGIN Found := TRUE; sStr := ‘’; pos := 0; WHILE Found DO BEGIN nStr := COPYSTR(nStr,pos+1); IF STRPOS(nStr,’ ‘) > 0 THEN BEGIN pos := STRPOS(nStr,’ '); sStr := sStr + COPYSTR(nStr,1,pos); END ELSE Found := FALSE; END; IF (((STRLEN(sStr) + STRLEN(nStr)) <= 30) AND ( i = ctr)) THEN sStr := sStr + nStr; Read += STRLEN(sStr); rectable.INIT; rectable.ctr := i; rectable.desc := sStr; rectable.INSERT; i += 1; oStr := COPYSTR(str, Read); IF STRLEN(oStr) > 30 THEN nStr := COPYSTR(str,Read+1 ,30) ELSE nStr := COPYSTR(str,Read+1); END Jagjeet

quote:


Originally posted by sjagjeet: But I think this will also cut down word in between.


No , it splits nicely. But anyway, I see you have found a more then valid alternative.

CLEAR(TXT); IF “Lin. Parte de Trabajo”.Descripción <> ‘’ THEN BEGIN xIAnt := ParteDescripción(COPYSTR(“Lin. Parte de Trabajo”.Descripción,1,38)); IF xIAnt <> 0 THEN TXT := COPYSTR(“Lin. Parte de Trabajo”.Descripción,1,xIAnt); END; IF STRLEN(“Lin. Parte de Trabajo”.Descripción) > 38 THEN MoreLines := TRUE ELSE MoreLines := FALSE; Function ParteDescripcion( Txt : text 250) integer J:= STRLEN(Texto); IF J < 38 THEN EXIT(J); REPEAT J := J-1; IF COPYSTR(Texto,J,1) = ’ ’ THEN EXIT(J); UNTIL J=1; EXIT(1); In other Integer dataintem IF xIAnt > STRLEN(“Lin. Parte de Trabajo”.Descripción) THEN CurrReport.BREAK; IF xIAnt + 38 < STRLEN(“Lin. Parte de Trabajo”.Descripción) THEN BEGIN IAnt := ParteDescripción(COPYSTR(“Lin. Parte de Trabajo”.Descripción,xIAnt,38)); TXT := COPYSTR(“Lin. Parte de Trabajo”.Descripción,xIAnt,IAnt); END ELSE BEGIN IAnt := 38; TXT := COPYSTR(“Lin. Parte de Trabajo”.Descripción,xIAnt, STRLEN(“Lin. Parte de Trabajo”.Descripción)-xIAnt); END; IF STRLEN(TXT) = 0 THEN CurrReport.BREAK; IF COPYSTR(TXT,1,1)=’ ’ THEN TXT := COPYSTR(TXT,2,STRLEN(TXT)); xIAnt := xIAnt + IAnt;

Hi Jagjeet, Please set the Multiline property of description field on the report. It will automatically wrap the word in multiple line.

hi rajesh, If you define the property of the control on the report as multiline. Than you have to define the height of the control. which is in my case is dynamic. i.e. I can have the description with 1 line or multi line. n if you define the control as multiline the than the control always take that much space on the report which i dont want. Cheers Jagjeet

hi, You can use multiple section with different field height & width and accordingly the contents of fields you can hide and show the section.

Hi Rajesh, What if tommorrow user say that he want the description to be 150 characters instead of 100 characters. Then again you are going to change all the reports i.e. sales orders, invoices, credit notes etc… Whereas if you use this thing you dont have to worry abt the length of the description. you can make it 150, 200 or make it back to 30 characters as standard. Regards Jagjeet

Hi, I am agree. But it is not good for the project if they changes the field length frequently. You can charge for the additional development. But it would be better to keep provision of more length in advance. Otherwise it would be the never end if and buts…