Crystal Report formulas

I have 2 formulas. One named 'Countclass' defined as below:

Shared Classcount as Number

If NextValue({COMMAND.PREFERRED_NAME_UPPER}) = {COMMAND.PREFERRED_NAME_UPPER} Then
    Classcount = Classcount + 1
End IF

Formula = Classcount

The other is 'Set Class Variable' shown below

Shared strClass1 as String
Shared strClass2 as String
Shared strClass3 as String
Shared strClass4 as String
Shared strClass5 as String
Shared strClass6 as String
Shared strClass7 as String
Shared strClass8 as String
Shared strClass9 as String
Shared strClass10 as String
Shared Classcount as Number

If  {@Classcount}= '1' then strClass1 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '2' then strClass2 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '3' then strClass3 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '4' then strClass4 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '5' then strClass5 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '6' then strClass6 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '7' then strClass7 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '8' then strClass8 = {COMMAND.CLASS_CODE}
   ELSE If  Classcount = '9' then strClass9 = {COMMAND.CLASS_CODE}    

I'm trying to count each class by which I will populate Detail field for student in report with each class they are taking each semester.
When I try and test , I get error saying 'A number , boolean, date time, currency amount, string is expected'.
Can someone help me with formulas ?
guinnieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
THe ClassCount formula returns a number.  Change the other formula to test for numbers not strings.
Crystal will not do any datatype conversions

Try this for 'Set Class Variable'
Shared strClass1 as String
 Shared strClass2 as String
 Shared strClass3 as String
 Shared strClass4 as String
 Shared strClass5 as String
 Shared strClass6 as String
 Shared strClass7 as String
 Shared strClass8 as String
 Shared strClass9 as String
 Shared strClass10 as String
 Shared Classcount as Number

 If  Classcount= 1 then strClass1 = {COMMAND.CLASS_CODE}
    ELSE If  Classcount = 2 then strClass2 = {COMMAND.CLASS_CODE}
    ELSE If  Classcount = 3 then strClass3 = {COMMAND.CLASS_CODE} 
    ELSE If  Classcount = 4 then strClass4 = {COMMAND.CLASS_CODE}
    ELSE If  Classcount = 5 then strClass5 = {COMMAND.CLASS_CODE}
    ELSE If  Classcount = 6 then strClass6 = {COMMAND.CLASS_CODE}
    ELSE If  Classcount = 7 then strClass7 = {COMMAND.CLASS_CODE}
    ELSE If  Classcount = 8 then strClass8 = {COMMAND.CLASS_CODE}
    ELSE If  Classcount = 9 then strClass9 = {COMMAND.CLASS_CODE}     

Open in new window


mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James0628Commented:
FWIW, I doubt that those formulas are going to work.  You're just putting CLASS_CODE in different variables, based on how many records have the same value in PREFERRED_NAME_UPPER.  You say that you want to "populate Detail field for student in report with each class they are taking each semester", and I don't see how those formulas are going to do anything like that.  But I could be wrong.

 FWIW2, instead of using the Classcount variable to count the records with the same PREFERRED_NAME_UPPER, you could theoretically create a group on PREFERRED_NAME_UPPER (you can suppress the group header and footer if you like) and then use a Count summary to get a count of the records in each group.  Whether or not that will work may depend on where the second formula is located.  Of course you can keep using the variable.  It just doesn't seem necessary.

 James
0
guinnieAuthor Commented:
Mimic was partially correct.  I didn't have to change the other strings to number variables. The If-then-else statements were correct. What actually worked was I retyped entire formula and then it tested and ran fine. Originally, I typed in notepad and pasted. Something was amiss doing that.

Thank you for your suggestions
0
James0628Commented:
mlmcc was correct.  You were trying to compare a number (Classcount) and strings (eg. '1'), and CR is always going to give you an error on that.  For example, a formula like this will give you an error:

if 1 = "1" then 1 else 0

 Typing in your formula again isn't going to change that.  I'm guessing that when you retyped the formula, you left out the quotes, which is exactly what mlmcc suggested in his post.

 However, there was also a second issue with your formula.  It looks like you were using Basic syntax, and the single quote (') is a remark indicator in Basic syntax.  So, on each line with single quotes, everything after the first single quote was ignored.  You can see that in the CR formula editor, because the commented text will be a sort of green, instead of blue (for keywords) or black.  That's actually what was giving you the error that you posted.

 You need to use double quotes around strings in Basic syntax, but in this case that would have just given you a different error, because then you'd be trying to compare numbers and strings.

 James
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.