PDA

View Full Version : DBase (Xbase) expression


dmacpher
11-29-04, 22:51
I have 2 fields in a form called Status and Type

If Status is = VERBAL AGR or WON then Type is = FORECAST
If Status is = OPEN then Type should be = WORKING
If Status is = ABANDONED then Type should be = CLOSED

The code below works for VERBAL AGR and WON and OPEN
What extra code do I need for testing the status ABANDONED ???????

iif((Contsupp->Contsupref=="Won", .AND. (Contsupp->Contsupref=="Verbal Agreement"), "FORECAST", "WORKING"))

amcamx
11-30-04, 18:00
I am ghetting some mixed ideas about what you are trying to accomplish. It appears from the information in the first paragraph you are tyring to assign values to TYPE (btw, type is a reserved word in FoxPro. I would not reccomend using it as a variable or field name as it can POSSIBLY cause problems later on.) based on the current value of STATUS (another reserved word.)

My reccommendation would be to NOT use the IIF() function as it is designed for a comparrison of 2 values (although you can add more depending on which version of FoxPro you are using but it gets to be very difficult to read).

What I would do instead would be to use the DO CASE statement as follows:

DO CASE

CASE STATUS = "VERBAL AGR" OR Status = "WON"
TYPE = "FORECAST"

CASE STATUS = "OPEN"
TYPE = "WORKING"

CASE STATUS = "ABANDONED"
TYPE = "CLOSED"

ENDCASE

Also, to make it a little better (to catch possible case sensitive issues and padded spaces) I would add the ALLTRIM() and UPPER() functions to the STATUS Field. for example: CASE ALLTRIM(UPPER(Status)) = "WORKING"


I hope this helps.

AmcAmx :)

RedAxl
11-30-04, 21:28
AmcAmx is right!
But if you really want to use Immediate If (IIF) for some reason,
here is what you need:

iif((Contsupp->Contsupref=="WON" .OR.
Contsupp->Contsupref=="VERBAL AGR"), "FORECAST",
iif(Contsupp->Contsupref=="OPEN", "WORKING", "CLOSE"))

NOTE:
-I used .OR. (according to your requirement) not .AND.

-Any value of Contsupp->Contsupref other than the tested values
will return "CLOSE"
You can trap this by adding additional IIF and
check if the value is "ABANDONED"