Jump to content

This topic is 7487 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I am trying to write a calculation that adds a carriage return so that lines of text will not exceed a fixed number of characters.

I got a calculation to start with from the Nightwing website (thank you Nightwing!)

But the calculation (below) does not seem to recognize when there already is a carriage return in the field being parsed. So, for example, what happens is:

LineBreakBefore (the global to set number of characters) = 20

Original Field:

Jane Johnson(carriage return)

10 University Plaza Park Northwest(carriage return)

Should Become:

Jane Johnson(original carriage return)

10 University Plaza(new carriage return)

Park Northwest(original carriage return)

But instead becomes:

Jane Johnson

10

University Plaza Park Northwest

Calculations are definitely my weak point, especially understanding how someone else's calculation already works. Hopefully this isn't totally obvious!

One potentially meaningful thing to know is that the field this calculation is processing ("Mailing Label") is itself already a calculation. Could this be a causing a problem?

Thanks for your help! I can't even put into words how grateful I am for this forum. Usually even my most complicated questions have already been answered and all I have to do is read past posts!

Here's the calculation from Nightwing:

Middle(Mailing Label, 1, Position(Middle(Mailing Label, 1, LineBreakBefore), " ", 1, PatternCount(Middle(Mailing Label, 1, LineBreakBefore), " ")) - 1) & "

Posted

I'm not sure what Ray was going for with his calculation, but this seems to work nicely.

Left( Mailing Label, Position( Mailing Label, " ", Position( Mailing Label, "

Posted

Thank you so much!! That works great. The only problem is that it is including in the count if there is a final space at the end of each line. So sometimes it is making an extra line when there isn't actually any text there. Would sticking Trim in the calculation somewhere fix that?

Posted

Sure. This is with LineBeforeBreak =46

Calculation:

Wellesley College

Center for Research on Women

128 Highland St.

W. Newton, MA 02465

Original:

Wellesley College

Center for Research on Women

128 Highland St.

W. Newton, MA 02465

Posted

Now that I look at it some more I think it actually isn't counting the number of characters on each line, but still counting the overall number of characters and breaking when it hits the set number. I could be getting confused though. At first I thought it was working right...

Posted

That one has four lines, which the calculation doesn't take into account. I think a repeating calc might work better for this. I'll work on it after lunch.

Posted

Okay, here's a sample that will split each line into two, if necessary, and then combine the parts back together for the label. This requires the LineBreakBefore to be a number, not a global, and the common global index to store rep numbers, as well as a lookup to copy the global index into a repeating number field that can be indexed, so that a value list can be created from the repeating calculation, sorted by the index number, forcing the split parts to be combined in the same order as the original label.

Note that this calculation assumes a single line should need to be split only once. If you have need for two possible splits per line, the calc will need to be tweaked for the additional possibility.

If you need more help, I should be around later tonight sometime.

Pittelman.zip

Posted

Wow. Thank you Queue!!! This is exactly what I needed. Wish there were a way to send a virtual beer over to you to say thanks for all the time you spent on this!

Posted

Thank you, but that's not necessary. It was boring at work on Friday. This gave me a challenge to keep me from passing out. So I should be sending you a beer, too. wink.gif

This topic is 7487 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.