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

Replicatestring Function

Status
Not open for further replies.

psamedy

Technical User
Apr 22, 2002
60
US
Hello

I'm trying to implement the Replicatestring function into my formula to create a fixed length string, but have not been successful. I'd like to make the data that is returned to look like they are in column format using Replicatestring and return to the next line after the third column. The built in column formatting option available in the detail section will not work for me. This is the formula i'm using now. Any help is appreciated. Pat

WhileprintingRecords;
StringVar Item := {@Description};
StringVar Chain;
NumberVar ChCnt;

if ChCnt = 1
then (ChCnt:= 2; Chain:= Item)
else
if length(Chain) + Length(Item) > 254
then Chain := Chain else
Chain := chain+', '+Item
 
Try something like:

WhileprintingRecords;
StringVar Item := {@Description};
StringVar Chain;
NumberVar ChCnt:=ChCnt+1;

if length(Chain) + Length(Item) > 254
then Chain := Chain
else if chcnt/3 = int(chcnt/3) then
Chain := chain+', '+Item+chr(13)
else if chcnt/3 <> int(chcnt/3) then
Chain := chain+', '+Item

-k
 
Please post what your data looks like and what you want the results to look like.

For this Replicatestring function into my formula to create a fixed length string,

The following formula would create a field the is 25 characters long, with -'s preceding your field.

replicatestring(&quot;-&quot;,25-length({yourfield})+{your.field}

Mike
 
Thank you, I'm closer now but with the formula posted by synapsevampire it is now shows the data like this:

Adam, Jennifer, Michael
Tiffany, Logan, Patricia
Jay, Karina, Kristen

I'd like it to look like this:

Adam Jennifer Michael
Tiffany Logan Patricia
Jay Karina Kristen

Thanks Pat
 
mbarron appears to have straightened that part out.

Since you had a comma in your script, I auumed that was how you wanted them.

-k
 
You can do this using 4 formulas. Then align the names.

The first creates an array to store the members of the field. The formula should be suppressed when added to the canvas.

@array
stringvar array names:=split({names.field},&quot;,&quot;);
&quot;&quot;

The three other formulas display the members of the array:
@name1
whileprintingrecords;
evaluateafter({@array});
stringvar array names;
names[1]

@name2
same as @name1 except last line is:
names[2]

@names3 -You know what to do [smile]

Lastly place the three names fields on the canvas, and your columns of names will line up.






Mike
 
Given that you're not limited to 3 names, if you use Mike's latest approach, you would presumably place all of the potential elements of the array in the report, and this assumes that you have some grouping, or some fashion by which you are limiting the number of elements.

So when you place the elements, create separate sections for each set of 3 elements, and suppress the sections based on the value of ubound(names), which is the number of elements in the array.

-k
 
The only way to get razor-sharp edges to your columns would be to do as Mike has suggested and use multiple formulas

You can vary the number of spaces between adjacent words to keep the number of characters the same but unless you are perhaps using a courir font this will still leave a ragged edge since usually the space allocation is different for each character.

Jim Broadbent
 
SV brings up a good point. I hadn't taken itno consideration that there may be more than 3 names. My approach assumes that each line (e.g. Adam, Jennifer, Michael) was a seperate field.

Mike
 
Thanks for the help, i'm not very familiar with arrays and varaibles so please excuse me if i ask silly questions.

When I apply your approach Mike i get an error message:

&quot;A subscript must be between 1 and the size of the array&quot; and it directs me to formula @Name3. What can I do?

Please keep in mind that,I'm trying to create the colums inside the body of a form letter that entirely exists within the details section. Pat
 
If my assumption about each line is a field, that means that the field only had two names.

Change the formula to this:

evaluateafter({@array});
stringvar array names;
if ubound(names)=3 then
names[3]else
&quot;&quot;

Mike
 
Originally, I had a variable accumulating the data from my field ({ppo_group.description)}for each letter in the details section which printed the data in the example i posted above. The variable was reset in the group header.

I've edited @name3 as u suggested and it returns the one and the same name for each letter.??Pat
 
I'm not sure what this menasit returns the one and the same name for each letter. Post examples please. The more we know the better we can help.

In the mean time, here is a formula that creates 3 columns, in one field with the start of each 20 characters wide.


stringvar array names:=split({@names},&quot;,&quot;);
stringvar n1;
stringvar n2;
stringvar n3;

n1:=names[1];
n2:=names[2];
if ubound(names)=3 then
n3:=names[3];

n1+replicatestring(&quot; &quot;,20-length(n1))+
n2+replicatestring(&quot; &quot;,20-length(n2))+
n3

Mike
 
Mike thanks, I think your formula is exactly what I need but I'm getting that error again: &quot;A subscript must be between 1 and the size of the array&quot;?
 
Try this one then:
stringvar array names:=split({@names},&quot;,&quot;);
stringvar n1;
stringvar n2;
stringvar n3;


if ubound(names)>=1 then
n1:=trim(names[1])
;
if ubound(names)>2 then
n2:=trim(names[2])
;
if ubound(names)=3 then
n3:=trim(names[3]);

n1+replicatestring(&quot; &quot;,20-length(n1))+
n2+replicatestring(&quot; &quot;,20-length(n2))+
n3

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top