Reputation: 6249
I am a newbie to Crystal Reports. I need to insert a variable calculated at runtime inside a string.
Example:
"You have $[VARIABLE] dollars left in your account"
Do I need to have three elements: the first part of the string "You have $", the variable, and the last part of the string "dollars left in your account"?
Or can I do something like String.Format, where I can insert the value during report generation?
Upvotes: 1
Views: 7375
Reputation: 4288
Is this in a parameter or just laid out on the form? There are two ways to do it.
First way, you can drag a label onto your report. Inside the label, you put "You have " then drag the field you want to move from the field explorer onto the label, then finish with " dollars left in your account.". That is assuming the database field doesn't need formatting. If it does, you can create a formula to format it (then drag the formula field in the same way). I like this way because you can kind see on your design view what it's going to look like, handy for large reports.
Second way, create a formula field to get the text and then drag it onto the form. You can use either "Crystal" or "Basic" syntax. I typically use basic just because I'm good at it and familiar with it. Example:
' Basic Syntax
If IsNull(zip_code) = false Then
formula = "Your zip code is " & {zip_code.zip_code}
Else
formula = "There is no zip code available."
End If
Upvotes: 2