Crystal Reports  

Comparing Basic Syntax Formulas with Functions in Visual Basic

The use of the formula variable is similar to writing a function named formula in Visual Basic.

Consider the following Basic syntax formula:

Rem A formula that returns a String value
Rem The function Rnd returns a random number
Rem between 0 and 1
If Rnd > 0.9 Then
   formula = "You won!"
Else
   formula = "Sorry, try again."
End If

The above formula returns the text string value "You won!" if the random number returned by Rnd is greater than 0.9 and the text string value "Sorry, try again." otherwise.

The above formula could be written as a Visual Basic function as follows:

Rem The following code is in Visual Basic
Function formula()
    If Rnd > 0.9 Then
       formula = "You won!"
    Else
       formula = "Sorry, try again."
    End If
End Function

See Also

Basic Syntax