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

Right Justify/Align 1 field in a formula

Status
Not open for further replies.

crogers111

Technical User
Jan 23, 2004
158
0
0
US
CR XI

I am combining 2 Strings fields and need to right justify the 2nd field. The first field can vary in length, the 2nd is one character.

e.g. of current output:

Sample Text M
Some More Samples M
other Samples M

Desired output

Sample Text M
Some More Samples M
other samples M

I have the text fields combined in a formula to solve another issue so would like to leave this way.

Thanks.
 
oops:

Desired output:

Sample Text M
Some More Samples M
other samples M


(all three M's should be lined up)
 
Maybe you should give more information.

Is the second field only one character? How many char space is the first field? You dont have to combine both fields. The first field is already left justified. And you only need to right justify the second field, if it more than one char.

Lin
 
Hey-

I would create a custom function that returns the number of spaces that are needed between field1 and field2 so that field2 is always in the same place. Something like this:

Function AddSpace (LengthOfField as Number) As String
Dim i as number
Dim SpaceHolder as string
For i = 0 to LengthOfField
SpaceHolder = SpaceHolder & " "
Next
AddSpace = SpaceHolder
End Function

Then in your formula where you are combining the strings, you would so something like this (if 20 was the number of spaces that were needed before field2). Not sure if there is an easier way or not, this is just what I would do.

Dim NumberOfSpacesNeeded as number
NumberOfSpacesNeeded = 20-Len({@Field1})
Formula = {@Field1} & addSpace(NumberOfSpacesNeeded) & {@Field2}
 
Thanks for the reply. I need the first field Left Justied and the second field below Right Justified within one formula if possible.

@CombinedFormula:

{LocationDesc.Description} & " " &{Data.ClaimType}


The problem I'm trying to solve is that this report is setup in BOE and is run to export to Plain Text. The last data field (furhtest right) is {Data.ClaimType} and somehow is not exporting and not being included in the export. so I'm trying to combine the last 2 data fields into one forumla as workaround but need to display as shown above.

 
You can't justify two fields differently, when concatenating. However, you can add or trim the spaces between fields to give you affect of left and right justify.

The other person answer is good too. Otherwise do this in a view.

Lin
 
Using Crystal syntax, you could use a formula like:

{table.field1}+replicatestring(" ", 25 -len({table.field1}+{table.field2}))+{table.field2}

...where 25 is the maximum length of the two fields combined plus a few spaces. You should also format the formula to a non-proportional font like Courier New.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top