Articles in this section
Category / Section

Equivalent SSRS-VB Expressions in Bold Reports for Crystal Syntax

Published:
Updated:

When migrating reports from Crystal Reports to Bold Reports, one of the key challenges is converting Crystal Syntax expressions into equivalent SSRS VB .NET code that Bold Reports supports. Crystal Reports provides built-in functions and a formula syntax that differ significantly from Bold Reports’ expression language, which relies on VB .NET and custom code blocks.

This Knowledge Base gives practical, side-by-side examples showing how to translate commonly used Crystal expressions into SSRS-compatible VB .NET code. Each entry includes:

  • The original Crystal Syntax
  • The equivalent Bold Reports VB Code
  • Instructions on how to use it in your report

Expression Equivalents: Crystal Syntax vs. SSRS VB Code

1. Correlation

Crystal Syntax: Correlation({field1}, {field2})

Bold Reports VB Code:

Add Custom Code to the Report

Dim xValues As New List(Of Double)
Dim yValues As New List(Of Double)

Public Sub AddValues(x As Double, y As Double)
xValues.Add(x)
yValues.Add(y)
End Sub

Public Function GetCorrelation() As Double
Dim n As Integer = xValues.Count
If n = 0 Then Return 0

Dim sumX As Double = 0
Dim sumY As Double = 0
Dim sumXY As Double = 0
Dim sumX2 As Double = 0
Dim sumY2 As Double = 0

For i As Integer = 0 To n - 1
sumX += xValues(i)
sumY += yValues(i)
sumXY += xValues(i) * yValues(i)
sumX2 += xValues(i) ^ 2
sumY2 += yValues(i) ^ 2
Next

Dim numerator As Double = (n * sumXY) - (sumX * sumY)
Dim denominator As Double = Math.Sqrt((n * sumX2 - sumX ^ 2) * (n * sumY2 - sumY ^ 2))

If denominator = 0 Then Return 0
Return numerator / denominator
End Function 

🧩 How to use it in the report

  1. Inside your Table or List, add a hidden TextBox and set its expression to:
=Code.AddValues(Fields!field1.Value, Fields!field2.Value) 
  1. Outside the data region (e.g., footer/header), add a TextBox with this expression:
=Code.GetCorrelation() 

2. Numeric Text

Crystal Syntax: NumericText (string)

Bold Reports VB Code:

Add this to the Code section of your report:

Function IsNumericText(val As Object) As Boolean
If val Is Nothing Then Return False
Dim strVal As String = val.ToString()
For Each ch As Char In strVal
If Not Char.IsDigit(ch) Then
Return False
End If
Next
Return True
End Function 

🧩 How to use it in the report

In your report expression (e.g., in a TextBox), use:

=Code.IsNumericText(Fields!YourField.Value) 

Returns True if the field contains only digits, otherwise False.


3. Description of value for the input parameter

Crystal Syntax: GetValueDescriptions ({?parameterfield})

Bold Reports VB Code:

If the parameter values and descriptions are fixed, you can hardcode them in the report’s Code section:

Function GetParameterDescription(val As String) As String
Select Case val
Case "A"
Return "Alpha"
Case "B"
Return "Beta"
Case "C"
Return "Gamma"
Case Else
Return "Unknown"
End Select
End Function 

Then use this in your report expression:

=Code.GetParameterDescription(Parameters!YourParameter.Value) 

4.Covariance

Crystal Syntax: Covariance({field1}, {table.field2})

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim xVals As New List(Of Double)
Dim yVals As New List(Of Double)

Public Function AddCovValues(x As Object, y As Object) As String
If Not x Is Nothing AndAlso IsNumeric(x) AndAlso Not y Is Nothing AndAlso IsNumeric(y) Then
xVals.Add(Convert.ToDouble(x))
yVals.Add(Convert.ToDouble(y))
End If
Return ""
End Function

Public Function GetCovariance() As Double
Dim n As Integer = xVals.Count
If n = 0 Then Return 0

Dim avgX As Double = xVals.Average()
Dim avgY As Double = yVals.Average()
Dim cov As Double = 0

For i As Integer = 0 To n - 1
cov += (xVals(i) - avgX) * (yVals(i) - avgY)
Next

Return cov / n
End Function 

🧩 How to use it

  1. Inside your data region (e.g., table or list), add a hidden TextBox with this expression:
=Code.AddCovValues(Fields!Field1.Value, Fields!Field2.Value) 
  1. Outside the data region, add a TextBox to display the result:
=Code.GetCovariance() 

5. Weighted average of the specified fields

Crystal Syntax: WeightedAverage({table.FIELD1}, {table.FIELD2})

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim values As New System.Collections.Generic.List(Of Double)
Dim weights As New System.Collections.Generic.List(Of Double)

Public Function AddWeightedValue(val As Object, weight As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) AndAlso Not weight Is Nothing AndAlso IsNumeric(weight) Then
       values.Add(Convert.ToDouble(val))
       weights.Add(Convert.ToDouble(weight))
   End If
   Return ""
End Function

Public Function GetWeightedAverage() As Double
   Dim weightedSum As Double = 0
   Dim totalWeight As Double = 0
For i As Integer = 0 To values.Count - 1
       weightedSum += values(i) * weights(i)
       totalWeight += weights(i)
   Next
If totalWeight = 0 Then
       Return 0
   Else
       Return weightedSum / totalWeight
   End If
End Function

🧩 How to use it

  1. Inside your data region (e.g., table or list), add a hidden TextBox with this expression:
=Code.AddWeightedValue(Fields!FIELD1.Value, Fields!FIELD2.Value) 
  1. Outside the data region, add a TextBox to display the result:
=Code.GetWeightedAverage() 

This will calculate the weighted average of FIELD1 using FIELD2 as the weight.


6. Median of the Given Numeric Fields

Crystal Syntax: Median(Field)

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim values As New List(Of Double)

Public Function AddValue(val As Object) As String
If Not val Is Nothing AndAlso IsNumeric(val) Then
values.Add(Convert.ToDouble(val))
End If
Return ""
End Function

Public Function GetMedian() As Double
If values.Count = 0 Then Return 0
values.Sort()
Dim count As Integer = values.Count
If count Mod 2 = 0 Then
Return (values(count \ 2 - 1) + values(count \ 2)) / 2
Else
Return values(count \ 2)
End If
End Function 

🧩 How to use it

  1. Inside your data region (e.g., table or list), add a hidden TextBox with this expression:
=Code.AddValue(Fields!YourField.Value) 
  1. Outside the data region, add a TextBox to display the result:
=Code.GetMedian() 

This will calculate the median of all numeric values in YourField.


7. Value for a specified percentile (P) in Number or Currency field

Crystal Syntax: PthPercentile(integer (0 to 100), {field})

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim percentileValues As New List(Of Double)

Public Function AddPercentileValue(val As Object) As String
If Not val Is Nothing AndAlso IsNumeric(val) Then
percentileValues.Add(Convert.ToDouble(val))
End If
Return ""
End Function

Public Function GetPercentile(p As Integer) As Double
If percentileValues.Count = 0 Then Return 0
percentileValues.Sort()
Dim rank As Double = (p / 100.0) * (percentileValues.Count - 1)
Dim lower As Integer = Math.Floor(rank)
Dim upper As Integer = Math.Ceiling(rank)

If lower = upper Then
Return percentileValues(lower)
Else
Return percentileValues(lower) * (upper - rank) + percentileValues(upper) * (rank - lower)
End If
End Function 

🧩 How to use it

  1. Inside your data region, add a hidden TextBox with:
=Code.AddPercentileValue(Fields!YourField.Value) 
  1. Outside the data region, add a TextBox to display the result:
=Code.GetPercentile(90)            'For 90th percentile          

You can change 90 to any percentile value (for example, 25, 50, or 75).


8. Nth Largest Value in a Given Field

Crystal Syntax: NthLargest(integer, {field})

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim nthValues As New List(Of Double)

Public Function AddNthValue(val As Object) As String
If Not val Is Nothing AndAlso IsNumeric(val) Then
nthValues.Add(Convert.ToDouble(val))
End If
Return ""
End Function

Public Function GetNthLargest(n As Integer) As Double
If nthValues.Count < n Then Return 0
nthValues.Sort()
nthValues.Reverse()
Return nthValues(n - 1)
End Function 

🧩 How to use it

  1. Inside your data region, add a hidden TextBox with:
=Code.AddNthValue(Fields!YourField.Value) 
  1. Outside the data region, add a TextBox to display the result:
=Code.GetNthLargest(3)                'For 3rd largest value 

You can change 3 to any Nth value you want to retrieve.


9. Nth Smallest Value in a Given Field

Crystal Syntax: NthSmallest(integer, {field})

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim nthSmallestValues As New List(Of Double)

Public Function AddNthSmallestValue(val As Object) As String
If Not val Is Nothing AndAlso IsNumeric(val) Then
nthSmallestValues.Add(Convert.ToDouble(val))
End If
Return ""
End Function

Public Function GetNthSmallest(n As Integer) As Double
If nthSmallestValues.Count < n Then Return 0
nthSmallestValues.Sort()
Return nthSmallestValues(n - 1)
End Function 

🧩 How to Use It in Your Report

  1. Inside your data region, add a hidden TextBox with:
=Code.AddNthSmallestValue(Fields!YourField.Value) 
  1. Outside the data region, add a TextBox to display the result:
=Code.GetNthSmallest(2)       'For 2nd smallest value 

You can change 2 to any Nth value you want to retrieve.


10. Most Frequently Occurring Value

Crystal Syntax: Mode({field})

Bold Reports VB.NET Code:

Add this code to the Code section of your report:

Dim modeValues As New System.Collections.ArrayList

Public Function AddModeValue(val As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) Then
       modeValues.Add(Convert.ToDouble(val))
   End If
   Return ""
End Function

Public Function GetMode() As Double
   If modeValues.Count = 0 Then Return 0

   Dim maxCount As Integer = 0
   Dim modeValue As Double = 0

   For i As Integer = 0 To modeValues.Count - 1
       Dim currentValue As Double = modeValues(i)
       Dim count As Integer = 0

       For j As Integer = 0 To modeValues.Count - 1
           If modeValues(j) = currentValue Then
               count += 1
           End If
       Next

       If count > maxCount Then
           maxCount = count
           modeValue = currentValue
       End If
   Next

   Return modeValue
End Function

🧩 How to Use It in Your Report

  1. Inside your data region, add a hidden TextBox with:
=Code.AddModeValue(Fields!YourField.Value) 
  1. Outside the data region, add a TextBox to display the result:
    VisualBasic
=Code.GetMode()

This will return the value that appears most frequently in YourField.


11. Nth Most Frequent Value in a Given Field

Crystal Syntax: NthMostFrequent(integer, {field})

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim freqValues As New System.Collections.ArrayList

Public Function AddFreqValue(val As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) Then
       freqValues.Add(Convert.ToDouble(val))
   End If
   Return ""
End Function

Public Function GetNthMostFrequent(n As Integer) As Double
   If freqValues.Count = 0 Then Return 0

   ' Create frequency map
   Dim uniqueValues As New System.Collections.ArrayList
   Dim counts As New System.Collections.ArrayList

   For i As Integer = 0 To freqValues.Count - 1
       Dim val As Double = freqValues(i)
       Dim found As Boolean = False

       For j As Integer = 0 To uniqueValues.Count - 1
           If uniqueValues(j) = val Then
               counts(j) = counts(j) + 1
               found = True
               Exit For
           End If
       Next

       If Not found Then
           uniqueValues.Add(val)
           counts.Add(1)
       End If
   Next

   ' Sort by frequency (bubble sort for compatibility)
   For i As Integer = 0 To counts.Count - 2
       For j As Integer = i + 1 To counts.Count - 1
           If counts(j) > counts(i) Then
               ' Swap counts
               Dim tempCount = counts(i)
               counts(i) = counts(j)
               counts(j) = tempCount

               ' Swap corresponding values
               Dim tempVal = uniqueValues(i)
               uniqueValues(i) = uniqueValues(j)
               uniqueValues(j) = tempVal
           End If
       Next
   Next

   If n > uniqueValues.Count Then Return 0
   Return uniqueValues(n - 1)
End Function

🧩 How to Use It in Your Report

  1. Inside your data region, add a hidden TextBox with:
=Code.AddFreqValue(Fields!YourField.Value) 
  1. Outside the data region, add a TextBox to display the result:
=Code.GetNthMostFrequent(2) 

You can change 2 to any Nth value you want to retrieve.


12. Get Lower Bound

Crystal Syntax: GetLowerBound(range)

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim dynamicList As New System.Collections.Generic.List(Of Integer)

Public Function InitializeArray(val As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) Then
       dynamicList.Add(Convert.ToInt32(val))
   End If
   Return ""
End Function

Public Function GetLowerBound() As Integer
   If dynamicList.Count = 0 Then Return -1
   Return 0
End Function

🧩 How to Use It in Your Report

  1. Call the below function in a TextBox to initialize the array.
=Code.InitializeArray(Fields!YourField.Value)
  1. Use the below function to display the lower bound
=Code.GetLowerBound()

13. Get Upper Bound

Crystal Syntax: GetUpperBound(range)

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim dynamicList As New System.Collections.Generic.List(Of Integer)

Public Function InitializeArray(val As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) Then
       dynamicList.Add(Convert.ToInt32(val))
   End If
   Return ""
End Function

Public Function GetUpperBound() As Integer
   If dynamicList.Count = 0 Then Return -1
   Return dynamicList.Count - 1
End Function

🧩 How to Use It in Your Report

  1. Call the following function in a TextBox to initialize the array.
=Code.InitializeArray(Fields!YourField.Value)
  1. Use the following function to display the upper bound.
=Code.GetUpperBound()

14. Has Lower Bound

Crystal Syntax: HasLowerBound(range)

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim dynamicList As New System.Collections.Generic.List(Of Integer)

Public Function InitializeArray(val As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) Then
       dynamicList.Add(Convert.ToInt32(val))
   End If
   Return ""
End Function

Public Function HasLowerBound() As Boolean
   If dynamicList Is Nothing Then Return False
   If dynamicList.Count = 0 Then Return False
   Return True                                'Lower bound of a list is always 0 if it has elements
End Function

🧩 How to Use It in Your Report

  1. Call the following function in a TextBox to initialize the array.
=Code.InitializeArray(Fields!YourField.Value)
  1. Use the following function to display the lower bound.
=Code.HasLowerBound()

15. Has Upper Bound

Crystal Syntax: HasUpperBound(range)

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim dynamicList As New System.Collections.Generic.List(Of Integer)

Public Function InitializeArray(val As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) Then
       dynamicList.Add(Convert.ToInt32(val))
   End If
   Return ""
End Function

Public Function HasUpperBound() As Boolean
   If dynamicList Is Nothing Then Return False
   If dynamicList.Count = 0 Then Return False
   Return True                                ' If the list has elements, it has an upper bound (Count - 1)
End Function

🧩 How to Use It in Your Report

  1. Call the following function in a TextBox to initialize the array.
=Code.InitializeArray(Fields!YourField.Value)
  1. Use the following function to check if the array has an upper bound.
=Code.HasUpperBound() 

16. Includes Lower Bound

Crystal Syntax: IncludesLowerBound(range)

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim dynamicList As New System.Collections.Generic.List(Of Integer)

Public Function InitializeArray(val As Object) As String
    If Not val Is Nothing AndAlso IsNumeric(val) Then
        dynamicList.Add(Convert.ToInt32(val))
    End If
    Return ""
End Function

Public Function IncludesLowerBound() As Boolean
    If dynamicList Is Nothing Then Return False
    If dynamicList.Count = 0 Then Return False
    Return True                                ' Lower bound is always 0 for List
End Function

🧩 How to Use It in Your Report

  1. Call the below function in a hidden TextBox to initialize the array.
=Code.InitializeArray(Fields!YourField.Value)
  1. Use the below function to check if the array includes a lower bound.
=Code.IncludesLowerBound()

17. Includes Upper Bound

Crystal Syntax: IncludesUpperBound(range)

Bold Reports VB Code:

Add this code to the Code section of your report:

Dim dynamicList As New System.Collections.Generic.List(Of Integer)

Public Function InitializeArray(val As Object) As String
   If Not val Is Nothing AndAlso IsNumeric(val) Then
       dynamicList.Add(Convert.ToInt32(val))
   End If
   Return ""
End Function

Public Function IncludesUpperBound() As Boolean
   If dynamicList Is Nothing Then Return False
   If dynamicList.Count = 0 Then Return False
   Return True                                ' If the list has elements, it has an upper bound (Count - 1)
End Function

🧩 How to Use It in Your Report

  1. Call the following function in a hidden TextBox to initialize the array.
=Code.InitializeArray(Fields!YourField.Value)
  1. Use the following function to check if the array includes an upper bound.
=Code.IncludesUpperBound() 

18. Print TimeZone

Crystal Syntax: PrintTimeZone()

Bold Reports VB Code:

Add this code to the Code section of your report:

Public Function GetTimeZone() As String
Return TimeZoneInfo.Local.DisplayName
End Function

🧩 How to Use It in Your Report
Add a TextBox with the following expression:

=Code.GetTimeZone()

This displays the local time zone of the server where the report is executed (e.g., UTC+05:30 Chennai, Kolkata, Mumbai, New Delhi).


19. Modification Date

Crystal Syntax: ModificationDate()

Bold Reports VB Code:

Add this code to the Code section of your report:

Function GetReportModifiedDate() As String
Try
Dim path As String = "C:\\Reports\\YourReport.rdl"
Dim info As New System.IO.FileInfo(path)
Return info.LastWriteTime.ToString("MM/dd/yyyy")
Catch ex As Exception
Return "Unknown"
End Try
End Function

🧩 How to Use It in Your Report

=Code.GetReportModifiedDate()

20. ModificationTime

Crystal Syntax: ModificationTime()

Bold Reports VB Code:

Add this code to the Code section of your report:

Function GetReportModifiedTime() As String
Try
Dim path As String = "C:\\Reports\\YourReport.rdl"
Dim info As New System.IO.FileInfo(path)
Return info.LastWriteTime.ToString("HH:mm:ss")
Catch ex As Exception
Return "Unknown"
End Try
End Function

🧩 How to Use It in Your Report

=Code.GetReportModifiedTime()

21. Report Comments

Crystal Syntax: ReportComments()

Bold Reports VB Code:

🧩 How to Use It in Your Report

Embed comments directly in a hidden TextBox and reference it using:

=ReportItems!TextboxComments.Value

22. Filename

Crystal Syntax: Filename()

Bold Reports VB Code:

Add this code to the Code section of your report:

Public Function GetReportFileName() As String
    Try        
        Dim path As String = "C:\\Reports\\YourReport.rdl"
        Dim info As New System.IO.FileInfo(path)
        Return info.Name
    Catch ex As Exception
        Return "Unknown"
    End Try
End Function

🧩 How to Use It in Your Report

Add a TextBox with the following expression:

=Code.GetReportFileName()

This will display the FileName (for example, YourReport.rdl).


23. File Creation Date

Crystal Syntax: FileCreationDate()

Bold Reports VB Code:

Add this code to the Code section of your report:

Function GetFileCreationDate() As String
Try
Dim path As String = "C:\\Reports\\YourReport.rdl"
Dim info As New System.IO.FileInfo(path)
Return info.CreationTime.ToString("MM/dd/yyyy")
Catch ex As Exception
Return "Unknown"
End Try
End Function

🧩 How to Use It in Your Report

=Code.GetFileCreationDate()

24. File Author

Crystal Syntax: FileAuthor()

Bold Reports VB Code:

If the author is static and known, you can hardcode it in a hidden TextBox and reference it:

=ReportItems!TextboxAuthor.Value

See Also

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