Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: selection coding "if" statement. Post Reply Post New Topic
Author Message
jsnm1
Newbie
Newbie


Joined: 02 Apr 2009
Location: United States
Online Status: Offline
Posts: 5
Quote jsnm1 Replybullet Topic: selection coding "if" statement.
     Posted: 02 Apr 2009 at 7:53am
Hi all,
 
This is my first post to this site.  I'm a non-tech person who is currently trying to use Crystal 10.  At a past job I used an earlier version of Crystal and am trying to refresh my memory regarding syntax.
 
Below is the "if" statement and error message I am getting.  The error occurs after the word "in" in the statement.
 
Can anyone help?  The coding for this selection used to work in the past!
 
if {IM1_InventoryMasterfile.ProductLine} in ["0037", "0041", "0045"] then formula = "Finished Goods" else formula = "Raw Materials"
 
error:
A number, currency amount, boolean, date, time, date-time, or string is expected here.
 
Jim
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Apr 2009 at 8:04am
Try it when you remove the "formula =" portions:
if {IM1_InventoryMasterfile.ProductLine} in ["0037", "0041", "0045"] then "Finished Goods" else "Raw Materials"
IP IP Logged
jsnm1
Newbie
Newbie


Joined: 02 Apr 2009
Location: United States
Online Status: Offline
Posts: 5
Quote jsnm1 Replybullet Posted: 02 Apr 2009 at 8:45am

Hi DBlank,

I'm still getting the same error message.

I actually put the "formula =" into the code to resolve a "A statement is expected here." message.
 
The "formula =" is new to me with this version.
 
Thanks,
 
Jim

 

 

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Apr 2009 at 8:56am

I first want to verify that you are creating a new formula field (or editing the one that is broken) and you want this formula field to return the string of either "Finished Goods" or"Raw Materials" depending on what the ProductLine is. Assuming this is correct...

You do not use that "formula=" syntax in the statement at all.
You just use "if condition then result else other result"
try and copy and paste this directly to resolve the issue:
if {IM1_InventoryMasterfile.ProductLine} in ["0037", "0041", "0045"] then "Finished Goods" else "Raw Materials"


Edited by DBlank - 02 Apr 2009 at 8:57am
IP IP Logged
jsnm1
Newbie
Newbie


Joined: 02 Apr 2009
Location: United States
Online Status: Offline
Posts: 5
Quote jsnm1 Replybullet Posted: 02 Apr 2009 at 9:06am
DBlank,
 
When I cut and paste from your post, I get the same message.  Your code is exactly the way I thought the code should be.
 
This problem is occurring in a "formula field".  When I use this code structure in the report selection, i.e., not imbedded in an "if" statement, it works fine.
 
Jim
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Apr 2009 at 9:09am

Ahhh. You cannot define data like that in the select statement.

What are you trying to accomplish with the selection?

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Apr 2009 at 9:39am
Oops, just re-read your post and inverted what you were saying. Sorry about that as the above is proabably a bit confusing Ermm
Most likely the problem is you have your formula field set to use Basic Syntax and not Crystal Syntax.
Flip it to Crystal Syntax.
 
 
IP IP Logged
jsnm1
Newbie
Newbie


Joined: 02 Apr 2009
Location: United States
Online Status: Offline
Posts: 5
Quote jsnm1 Replybullet Posted: 02 Apr 2009 at 9:42am
I am just trying to create a new field that I can use in the report to tell the me whether an item should be coded as a finished good or raw material based upon the product code assigned to the item.
 
Basically I am trying to clean up an item master that has been neglected for a few years.
 
Jim
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Apr 2009 at 9:45am
Yep. Sorry about the confusion as I incorrectly assumed you were using Crystal Syntax in the formula field.
Copy and Paste the above version of the formula but set the formula option to use the Crystal Syntax.

Edited by DBlank - 02 Apr 2009 at 9:45am
IP IP Logged
jsnm1
Newbie
Newbie


Joined: 02 Apr 2009
Location: United States
Online Status: Offline
Posts: 5
Quote jsnm1 Replybullet Posted: 02 Apr 2009 at 10:50am
Thanks for your help.
 
Jim
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