Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula Fields If Statement Post Reply Post New Topic
Author Message
winderm
Newbie
Newbie


Joined: 12 Oct 2010
Location: United States
Online Status: Offline
Posts: 2
Quote winderm Replybullet Topic: Formula Fields If Statement
     Posted: 12 Oct 2010 at 8:38am
I'm working on creating my very first report in Crystal Reports, and have gotten caught up trying to display text in an object based on an underlying if statement.

Hopefully I'm not way off base, but it is my understanding that I'll have to use a Formula Field in order to get it to display.

I've created one with the following code:

StringVar stat;
If {EventMeetingsReportView.MeetingStatus} = "Cancelled" Then
    stat = "Has Been Cancelled"
Else 
    stat = {RoomsReportView.Building} & ", room " & {RoomsReportView.RoomNumber};

I have a text object with the field in it, but when preview the form all it displays is "False".  Any insight would be greatly appreciated - thanks!
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 12 Oct 2010 at 9:18am
Try:
 
StringVar stat:=(If {EventMeetingsReportView.MeetingStatus} = "Cancelled"
     Then "Has Been Cancelled"
          Else {RoomsReportView.Building} & ", room " & {RoomsReportView.RoomNumber});

stat;




Edited by FrnhtGLI - 12 Oct 2010 at 9:18am
|< /\ '][' ( )
IP IP Logged
rvink
Groupie
Groupie
Avatar

Joined: 04 Feb 2008
Location: New Zealand
Online Status: Offline
Posts: 55
Quote rvink Replybullet Posted: 12 Oct 2010 at 1:20pm
If you are using Crystal syntax "=" is used only for comparison. The statement
   stat = "Has Been Cancelled"
is false (stat does not equal "Has been Cancelled"). If you want to assign a value to a variable use ":=" instead:

If {EventMeetingsReportView.MeetingStatus} = "Cancelled" Then
    stat := "Has Been Cancelled"
Else 
    stat := {RoomsReportView.Building} & ", room " & {RoomsReportView.RoomNumber};

This one catches me out all the time, I often switch to Basic syntax instead which does not have this problem.

Actually, if the variable stat is not needed for further calculations in the formula you can leave it out and do this:

If {EventMeetingsReportView.MeetingStatus} = "Cancelled" Then
    "Has Been Cancelled"
Else 
    {RoomsReportView.Building} & ", room " & {RoomsReportView.RoomNumber};




Edited by rvink - 12 Oct 2010 at 1:23pm
IP IP Logged
winderm
Newbie
Newbie


Joined: 12 Oct 2010
Location: United States
Online Status: Offline
Posts: 2
Quote winderm Replybullet Posted: 13 Oct 2010 at 5:57am
All the solutions provided seem to give solid results - thanks for helping me along.  I think I'm starting to grasp the logic of Crystal syntax - hopefully I won't have to come back asking for help too often.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum