INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Dynamically changing column widths in Crystal XI

## Dynamically changing column widths in Crystal XI

(OP)
thread222-814729: Crystal report & Resizing column width while runtime ?

I had to create some dynamic columns based on an unknown number of fields being used. Here's the Crystal Formula I set up in the header and suppressed. I hope it helps. We knew there would never be more than 10 columns, but typically less than 10 columns. It will dynamically set the empty ones to a 0 width and resize the remaining ones and set the remaining ones. It's complicated, ugly and a royal pain, but it gets the job done and might save someone a little bit of headache. The reason for the nasty formula at the end is simply to see the column widths while making the formula. Check the formula button and use this code for the X location changing the index from 1 to 2 to 3 .... based on which item you wish to show:

Shared ColumnsLeft(10) As Number
Formula = ColumnsLeft(1)

and this for the width:

Shared ColumnWidth As Number
Formula = ColumnWidth

Once you have it working, just suppress the formula and it's all good.

The Shared variables are so that you can set the column widths and locations in the size and position of the particular field. Simply make the formula use BASIC syntax and share each of the variables and you can then dynamically position as needed.

Shared TotalColumns As Number
Shared ColumnWidth As Number
Shared ColumnsLeft(10) As Number
Dim LoopIndex As Number
Dim StaticColumnWidth As Number
Dim Pixels As Number
Pixels = 1440
TotalColumns = 0

If (Not IsNull({Eval_EvaluationReportShared;1.Header01})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header02})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header03})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header04})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header05})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header06})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header07})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header08})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header09})) Then TotalColumns = TotalColumns + 1
If (Not IsNull({Eval_EvaluationReportShared;1.Header10})) Then TotalColumns = TotalColumns + 1

If( TotalColumns > 0) Then
ColumnWidth = 5.50 / TotalColumns 'The Left Side Of The Mean Is 9.200. The Right Side Of Question Text Is 3.200, Thusly 6.000. We Can Set The ColumnWidth = 6.000 / TotalColumns.
End If

'StaticColumnWidth = ColumnWidth 'Just Holds To Keep A Possible Accumulator Problem From Happening.
' The New Columns Will Become The New Left Based On Crystal's .Left Function Moving A Number Of Pixels To The Right. Also, The Distance Being In Pixels Makes Us Multiply It By 1440.
'ColumnsLeft(1) = 0 'Column Number 1 NEVER Changes Regardless Of The Number Of Columns.
For LoopIndex = 1 To 10
'If (TotalColumns >= LoopIndex) Then
'ColumnsLeft(LoopIndex) = 0
ColumnsLeft(LoopIndex) = (LoopIndex - 1) * ColumnWidth * Pixels * 1.05 'The New Column Width Is Calculated, Remove The Original .58 Width, Then Multiply By Pixels Per Inch (1440).
If (LoopIndex > TotalColumns) Then ColumnsLeft(LoopIndex) = 0 'This Is To Keep The Row From Getting Too Wide.
Next LoopIndex
'Make The Pixel Conversion Now (Pixels Are 1440 Per Inch Which The Calculations Above Are Made On).
ColumnWidth = ColumnWidth * Pixels * 0.50
If (TotalColumns = 0) Then ColumnWidth = 390 'This Is The Default Size For 10.
Formula = "TotalColumns: " & ToText(TotalColumns, "#0") & ", ColumnWidth: " & ToText(ColumnWidth, "#0.000") & ", CL(1) = " & ToText(ColumnsLeft(1), "0") & ", CL(2) = " & ToText(ColumnsLeft(2), "0") & ", CL(3) = " & ToText(ColumnsLeft(3), "0") & ", CL(4) = " & ToText(ColumnsLeft(4), "0") & ", CL(5) = " & ToText(ColumnsLeft(5), "0") & ", CL(6) = " & ToText(ColumnsLeft(6), "0") & ", CL(7) = " & ToText(ColumnsLeft(7), "0") & ", CL(8) = " & ToText(ColumnsLeft(8), "0") & ", CL(9) = " & ToText(ColumnsLeft(9), "0") & ", CL(10) = " & ToText(ColumnsLeft(10), "0")

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!