Search code examples
vb.netvbscriptcrystal-reportscrystal-reports-xi

Error "The Remaining Text Does Not Appear To Be Part Of The Formula" Crystal Reports 11.5.8.826


I'm receiving the error stated in the question title in Crystal Reports. I've been troubleshooting for a while and I'm drawing blanks. I have some simple If..Then..Else statements and Select..Case statements in separate formulas, but I'm receiving the same errors for all of them. I'm writing the formulas in VB.Net and I suspect the issue is stemming from how I'm declaring my variables.

An example of a formula is:

Dim xyz As Number = {VALUE1} 
Dim array1 = New Integer() {1111, 1112, 1214, 1215} 
Dim array2 = New Integer() {1211, 1212, 1213, 1414, 1415} 
Dim array3 = New Integer() {1311, 1312, 1514, 1515} 
Dim array4 = New Integer() {1911} 

If Array.IndexOf(array1, xyz) >= 0 Then
    {VALUE2} & "_001"
ElseIf Array.IndexOf(array2, xyz) >= 0 Then
    {VALUE2} & "_002"
ElseIf Array.IndexOf(array3, xyz) >= 0 Then
    {VALUE2} & "_003"
ElseIf Array.IndexOf(array4, xyz) >= 0 Then
    {VALUE2} & "_004"
Else
    {VALUE2}
End If

When I enter that formula into the selected field it highlights everything after the = sign on line 1 (Dim xyz As Number =...).

After searching I've tried the use of colons with equal signs (:=) and semi-colons to end if statement, but couldn't find much more online to guide me. I did find threads suggesting a .dll may be missing, but I don't currently have write permissions to a lot of areas on the system I'm working with so any fix like that is out of question for me.

My question in short is why am I receiving this error? Is it my If..Then..Else syntax or how I'm declaring variables? Or am I just not supposed to use VB.Net in crystal reports like I am doing?


Solution

  • Crystal does support a Basic Syntax, but it is more akin to VBA or VB6 than .Net, and also has its own peculiarities and limitations.

    • No initalization on declaration
    • Return value is "Formula =", it is not implied as in Crystal Syntax.
    • Most functions and operators are more like the Crystal Syntax than regular basic.
    • All return values need to be of the same type.

    Here is what I think you were going for:

    Dim xyz As Number
    Dim array1() as number
    Dim array2() as number
    Dim array3() as number
    Dim array4() as number
    
    xyz = {VALUE1}
    array1 =  array(1111, 1112, 1214, 1215)
    array2 = array(1211, 1212, 1213, 1414, 1415)
    array3 = array(1311, 1312, 1514, 1515)
    array4 = array(1911)
    
    If  (xyz in array1) Then
        Formula = {VALUE2} & "_001"
    ElseIf (xyz in array2) Then
        Formula = {VALUE2} & "_002"
    ElseIf (xyz in array3) Then
        Formula = {VALUE2} & "_003"
    ElseIf (xyz in array4) Then
        Formula = {VALUE2} & "_004"
    Else
        Formula = totext({VALUE2})
    End If