Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prob With Formula(urgent reply pls) 1

Status
Not open for further replies.

longfellow

IS-IT--Management
Mar 28, 2002
75
IN
I have various students in a course . I have a statement in the report where i mention regarding male/female participants were there in the course.
-----------------------------------------------------------
I use the following formula
StringVar Sex;
if {STUD_SEX.SEX} = "M" then
if {STUD_SEX.SEX} = "F" then
Sex:= " male/female"
else
Sex:= " male"
else
Sex:= " female"
-----------------------------------------------------------

I will have 3 scenarios.First
male students:- if all paticipants attending the particular course are "males".
then the formula should return "male"
female students:- if all paticipants attending the particular course are "females".
then the formula should return "female"
male and female students:- if all paticipants attending the particular course include "males and females. "
then the formula should return "male/female"
-----------------------------------------------------------
I tried using the above formula
the first 2 scenarios are working fine but when it comes to the third ie when bot hmale and female participants are there instead of givinge "male/female" as the output i get output on 2 seperate lines
"male"
"female"
Whats wrong with the formula? how do i get the third scenario working? can't i have all the 3 in same formula?
Can anybody help me immdly

Thanking you in Advance
Longfellow


 
In Crystal, a formula creates a column, and the variable is reassigned on each record. You are trying to evaluate the group, not the record. Try this, assuming that the SEX field is always filled in:

if Minimum ({STUD_SEX.SEX}, {Table.Course}) <>
Maximum ({STUD_SEX.SEX}, {Table.Course})
then &quot;Male/Female&quot; else
if Maximum ({STUD_SEX.SEX}, {Table.Course}) = &quot;M&quot;
then &quot;Male&quot;
else &quot;Female&quot;

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
When i used the above mentioned formula
if Minimum ({STUD_SEX.SEX}, {Table.Course}) <>
Maximum ({STUD_SEX.SEX}, {Table.Course})
then &quot;Male/Female&quot; else
if Maximum ({STUD_SEX.SEX}, {Table.Course}) = &quot;M&quot;
then &quot;Male&quot;
else &quot;Female&quot;

it was returning the error
&quot;The summary/running total field could not be created&quot;
and another error
at
Maximum ({STUD_SEX.SEX},
&quot;There should be a group that matches this field&quot;

Whats the problem

Thanking you in Advance

Longfellow
 
What about using your global variable sex.

Global StringVar Sex;
If {Stud_Sex.sex} = &quot;M&quot; and Sex = &quot;Male&quot; then Sex := &quot;Male&quot;
Else if {Stud_Sex.sex} = &quot;M&quot; and Sex = &quot;Female&quot; then Sex := &quot;Male/Female&quot;
Else if {Stud_Sex.sex} = &quot;F&quot; and Sex = &quot;Male&quot; then Sex := &quot;Male/Female&quot;
Else if {Stud_Sex.sex} = &quot;F&quot; and Sex = &quot;Female&quot; then Sex := &quot;Female&quot;

Hope this helps

 
Longfellow,

You have to put your own group field into the formula where I put the {Table.Course} field. I assume that you are doing this for each group in the report.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Dear ken

I did'nt understand what you meant by group field. The values i am trying to return is from the database and it is returned into a formula in a subreport. I tried the above mentioned formula with global variable . But it does'nt return any output. One of my colleagues was saying as the initial value of variable sex is null noting is being returned . What might be the problem?

Thanking you in advance

longfellow
 
What about using your global variable sex.

Global StringVar Sex;
Add in a few lines to account for those occasions when the variable is null.
If Sex = &quot;&quot; then
If {Stud_Sex.sex} = &quot;M&quot; then
Sex := &quot;Male&quot;
Else if {Stud_Sex.sex} = &quot;F&quot; then
Sex := &quot;Female&quot;
Else If {Stud_Sex.sex} = &quot;M&quot; and Sex = &quot;Male&quot; then Sex := &quot;Male&quot;
Else if {Stud_Sex.sex} = &quot;M&quot; and Sex = &quot;Female&quot; then Sex := &quot;Male/Female&quot;
Else if {Stud_Sex.sex} = &quot;F&quot; and Sex = &quot;Male&quot; then Sex := &quot;Male/Female&quot;
Else if {Stud_Sex.sex} = &quot;F&quot; and Sex = &quot;Female&quot; then Sex := &quot;Female&quot;
You may need to make some modifications to the code (eg putting in ; if required. Test it to see what happens.
Hope this helps

 
Is this formula in the main report or subreport?
Is the sex field in the main report or subreport?
Is the course field main report or subreport?
Is the main report gouped by course or is the whole report for one course? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
The formula is in a sub report .And the sex field is the only field in it. Actually there is no course field as such being used . I will just display a staement as follows:
&quot;Twenty male/female students participated in the project&quot;
I only add the sex part here . the remaining things are all static text in the formula . Thats all. The link between this subreport and main report is based on Project Number
Thats it . Can you help me now.

Thanking you

Longfellow
 
Try this formula in the subreport:

if Minimum ({STUD_SEX.SEX}) <>
Maximum ({STUD_SEX.SEX})
then &quot;Male/Female&quot; else
if Maximum ({STUD_SEX.SEX}) = &quot;M&quot;
then &quot;Male&quot;
else &quot;Female&quot; Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Thank you very much for this input .Finally the problem is solved .The formula worked out. thanks a lot my bug was fixed .

Longfellow

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top