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

static length variable

Status
Not open for further replies.

kims212

Programmer
Dec 17, 2007
103
CA
CRXI - windows 7

I have two arrays, one string and one numeric, about 20 elements in each array

I create one long string of values from each array, as follows:

toc_listing_shared:='';
i:=0;
part1:='';
part2:=replicatestring('.',80);
part3:='';
do
( i:=i+1;

part1:=left(trim(industry_name_shared)+space(30),30);
part2:=totext(industry_page_no_shared,0);

toc_listing_shared := toc_listing_shared + part1 + ' ' + part2 + ' ' + part3 + chr(10) + chr(10);
)
while i<={#group_position_in_array}-1;

yes, I am trying to create a table of contents, for our industry directory.

because of the chr(10) + chr(10), on the report I get 20 lines of:

Industry name .................................................... pg#
Industry name .................................................... pg#
Industry name .................................................... pg#

the names and page #s are correct, but, because the industry names are different lengths, part2 (............) needs to be a different
length for each line, and because letters are of different widths, left(trim(industry_name)+space(30),30) doesn't work either, the page #s are not aligned.

so what I get, is more like this:

Industry name AAAAAA ......................................... 1 ( with the space between the industry name and the beginning
Industry name BBBBBBBBB ............................................... 3 of the ... which doesn't seem to show up here in the preview )
Industry name CC ............................................. 7

is there a way to force a variable to maintain a static 'physical' width or # of letters with equal width despite the value it contains? I realize that the '.....' wouldn't necessarily start immediately after the industry name as shown above, but it's more important that the page #s are aligned to the right.

i.e.

Industry name AAA .......................................................... 1
Industry name BBBBBBBBBBB ............................................. 3
industry name CCCCCCC .................................................. 7

this doesn't show up proerply here in the post and what I attempted to show, was the ...... all the same length with a space between the industry name and the beginning of the .........


of course it would be ideal to have:

Industry name AAA .......................................................... 1
Industry name BBBBBBBBBBB ............................................. 3
industry name CCCCCCC .................................................. 7

but I'm not hoping for a miracle.

any assistance would be gretly appreciated.

thank you
kim






 
Try initializing part2 in the do..while statement and subtracting the length of part1 and the length of part3 from 80. Then concatenate the page number to the part2 variable. Also, I removed the 30 spaces from part1 because I don't think you'll need that doing it this way. This should allow the "..." to grow and shrink with the number of characters in part1 and 3. I don't have crystal on this pc so there may or may not be some errors.

Code:
toc_listing_shared:='';
i:=0;
part1:='';
part2:='';
part3:='';
do
( i:=i+1;
  
  part1:=trim(industry_name_shared[i]);  
  part2:=replicatestring('.',80-(length(part1)+length(part3)));
  part2:=part2+totext(industry_page_no_shared[i],0);
  

toc_listing_shared := toc_listing_shared + part1 + ' ' + part2 + ' ' + part3 + chr(10) + chr(10);
)
while i<={#group_position_in_array}-1;
 
hi born2program

Thanks for your response.

i'm out of the office this week so i can't try out your suggestion but am anxious to do so when i'm back next week - not too anxious to get back to work, mind.

one thing, i forgot to set a value for part3, so i'm assuming that we both intended it to be totext(industry_page_no_shared.

this may seem a daft question, but will the len() function overcome the problem of some characters taking up less space than others?

well, as i say, i won't get to try it out until next week, so will update then.

thanks again.

kim.

.




will
 

I finally was able to get on a pc with crystal and have updated the code a bit to allow for part3. The use of the length() function will overcome the issue with some characters taking up less space than others. However, if everything still doesn't space out the same then do the following: Right click the field on the report, Click "Format Field...", Go to the "Font" tab, Change the value for "Character Spacing Exactly:" to 5.

Code:
toc_listing_shared:='';
i:=0;
part1:='';
part2:='';
part3:='';
do
( i:=i+1;
  
  part1:=trim(industry_name_shared[i]);  
  part2:=replicatestring('.',80-(length(part1)+length(part3)));
  part3:=totext(industry_page_no_shared[i],0);
  

toc_listing_shared := toc_listing_shared + part1 + ' ' + part2 + ' ' + part3 + chr(10) + chr(10);
)
while i<={#group_position_in_array}-1;
 
hi born2porgram

thanks again for your response. just back from today - moan - and still dealing with administrivia before i get down to the good stuff, but first, I do have a question: to which field are you referring when you say, "right click on the field on the report"? do you mean the page # or is length 5 just an example of what can be done?

thx
kim
 
hi born2program

thanks so much for your suggestion. changing the character spacing to exactly 5 worked and now the table of contents is lined up just as I wanted it.

I do still have one little problem; the leftmost letter in the field - first letter in the industry name - seems to be cut off a bit on the wider letters: A, M, W, O etc. i put a space at the beginning of the industry name in the string that i put on the report, but then the left side of the industry names weren't lining up. they aren't really lined up as it is, but with the letters cut off a bit, it's not quite as obvious. I think that the narrower letters line up with the centre line of the wider letters so their left hand side is indented just that bit and don't get cut off.

do you have any ideas to fix that? i'm not what you'd call an expert and stumble on things like this. perhaps it's a matter of playing around with fonts.

I have another problem but i'll post it in a different thread.

anyway, thank you so much for your very helpful suggestion - and the time that it takes to offer your help on the forum.

kims
 
You could use a non-proportional font like Courier New.

-LB
 
thanks lb, I'll try that. this directory & toc has certainly been a process of evolution.

kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top