Articles in this section
Category / Section

How to Truncate Text Using Custom VB Code in Bold Reports

Published:
Updated:

Bold Reports offers a feature that allows you to truncate excessively long text within tablix cells using custom VB code. This approach limits the number of characters displayed and automatically appends an ellipsis (…) when the text exceeds the defined limit. It helps maintain a clean, readable layout, especially useful for fields like user feedback or detailed descriptions with variable lengths.

Steps to Implement Text Truncation
Adding Custom VB Code
  1. Access the Properties panel
    • Open the Properties panel in the Report Designer and click on the Settings Icon to open the report properties
      image.png
  2. Navigate to the Code section
    • Expand the Code section and click on Code to open the Code Editor.
      image.png
  3. Set the Custom VB Code
    • Use the following code in the Code Module and click OK to save.
Function TruncateString(ByVal input As String, ByVal length As Integer) As String
    If input.Length > length Then
        Return Left(input, length) & "..."
    Else
        Return input
    End If
End Function
Code Description
Declaration: Function TruncateString(ByVal input As String, ByVal length As Integer) As String Declares a function that takes a string and a length, and returns a truncated string.3
Condition: If input.Length > length Checks if the input string exceeds the specified length.
Truncate: Return Left(input, length) & "..." Returns the first length characters followed by an ellipsis if the string is too long.
Adding the Expression
  1. Setting the Expression in the Tablix Cell:
    • Open the Expression Editor from the desired tablix cell. Enter the following expression and click OK to apply
      image.png

      image.png
    =Code.TruncateString(Fields!YourFieldName.Value, 10)
    

The expression =Code.TruncateString(Fields!YourFieldName.Value, 10) calls the TruncateString function to limit the YourFieldName field to 10 characters, appending “…” if longer, or returning the full string if shorter.

  1. Preview
    • Before Configuration: The full text is displayed, potentially causing layout issues.
      image.png
    • After Configuration: The text is truncated to 10 characters with an ellipsis for longer strings.
      image.png
Conclusion

Using custom VB code in Bold Reports to truncate text ensures that your report layout remains tidy and professional. This method is especially effective for handling fields with unpredictable or lengthy content, improving both usability and visual appeal.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied