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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if - elif -elif -else

Status
Not open for further replies.

fishman13

Programmer
Jul 8, 2002
73
0
0
US
Does Foxpro support this syntax. I keep getting an sytax error, but they all appear as keyword.

I am trying to do the

if (condition 1)
do something
elif (condition 2)
do something
elif (condition 3)
do something
else
do something
endif

thanks
 
To do this in foxpro:

SELECT CASE
CASE <condition 1>
<do something>
CASE <condition 2>
<do something>
OTHERWISE
<do something>
END CASE

Unlike other languages this statement does not test equality with a single value, but re-evaluates a boolean expression for each case.
 
The case won't work with the way I have the if currently coded (see below). Does FoxPro support any other loops without using multiple nested if statements

if (NOT((isblank(thisform.txt_lname.value)) AND ;
(isblank(thisform.txt_fname.value)) AND ;
(isblank(thisform.txt_mname.value)) ))
select lname, fname, mname, account, address1, ;
address2, city, state, zipcode , ;
homephone, workphone, social, ;
birthdate, sex from patfile ;
where trim(lname) = ;
trim(thisform.txt_lname.value) ;
into CURSOR csrtemp
elif ( NOT (isblank(thisform.txt_dob.value)))
select lname, fname, mname, account, address1, ;
address2, city, state, zipcode , ;
homephone, workphone, social, ;
birthdate, sex from patfile ;
where trim(dob) = ;
trim(thisform.txt_dob.value) ;
into CURSOR csrtemp
elif ( NOT (isblank(thisform.txt_chart.value)))
select lname, fname, mname, account, address1, ;
address2, city, state, zipcode , ;
homephone, workphone, social, ;
birthdate, sex from patfile ;
where trim(chart) = ;
trim(thisform.txt_chart.value) ;
into CURSOR csrtemp
endif
 
Do not understand why CASE would not work for you. By looking at your code it should work fine using a case

If the first one is true it will do it and non of the rest and so on

CASE lExpression1 Commands ...
[LI]When the first true (.T.) CASE expression is encountered, the set of commands following it is executed. Execution of the set of commands continues until the next CASE or ENDCASE is reached. Execution then resumes with the first command following ENDCASE.
[LI]If a CASE expression is false (.F.), the set of commands following it up to the next CASE clause is ignored.
[LI]Only one set of commands is executed. These are the first commands whose CASE expression evaluates to true (.T.). Any succeeding true (.T.) CASE expressions are ignored.

OTHERWISE Commands
[LI]If all of the CASE expressions evaluate to false (.F.), OTHERWISE determines if an additional set of commands is executed.
[LI]If you include OTHERWISE, the commands following OTHERWISE are executed and execution skips to the first command following ENDCASE.
[LI]If you omit OTHERWISE, execution skips to the first command following ENDCASE
 
The syntax is:

DO CASE
CASE <CONDITION>
<some code>
OTHERWISE
<somecode>
ENDCASE

Select case is VB syntax.

Be aware fo the following:
in a condition like:
IF condition A AND Condition B
ENDIF

If condition A evaluates to False, the second condition is not evaluated anymore (as where in VB it is !!)

HTH,

Weedz (Edward W.F. Veld)
My private project:Download the CrownBase source code !!
 
Forgive me if I'm missing something here, but either of these should work:

Code:
IF (NOT((isblank(thisform.txt_lname.value)) AND ;
        (isblank(thisform.txt_fname.value)) AND ;
        (isblank(thisform.txt_mname.value)) ))
           select lname, fname, mname, account, address1, ;
                  address2, city, state, zipcode , ;
                  homephone, workphone, social, ;       
                  birthdate, sex from patfile ;
                  where trim(lname) = ;
                  trim(thisform.txt_lname.value) ;
                  into CURSOR csrtemp 
ELSE
   IF ( NOT (isblank(thisform.txt_dob.value)))
         select lname, fname, mname, account, address1, ;  
                 address2, city, state, zipcode , ;
                 homephone, workphone, social, ;
                 birthdate, sex from patfile ;
                 where trim(dob) = ; 
                 trim(thisform.txt_dob.value) ;
                 into CURSOR csrtemp
   ELSE
      IF ( NOT (isblank(thisform.txt_chart.value)))
          select lname, fname, mname, account, address1, ;
                  address2, city, state, zipcode , ;
                  homephone, workphone, social, ; 
                  birthdate, sex from patfile ;
                  where trim(chart) = ; 
                  trim(thisform.txt_chart.value) ;
                  into CURSOR csrtemp
      ELSE
         MESSAGEBOX(&quot;Nothing to query&quot;, 6, &quot;Parameters don't qualify&quot;)    
      ENDIF
   ENDIF
ENDIF   


DO CASE 
   CASE (NOT((isblank(thisform.txt_lname.value)) AND ;
             (isblank(thisform.txt_fname.value)) AND ;
             (isblank(thisform.txt_mname.value)) ))
           select lname, fname, mname, account, address1, ;
                  address2, city, state, zipcode , ;
                  homephone, workphone, social, ;       
                  birthdate, sex from patfile ;
                  where trim(lname) = ;
                  trim(thisform.txt_lname.value) ;
                  into CURSOR csrtemp 

   CASE ( NOT (isblank(thisform.txt_dob.value)))
         select lname, fname, mname, account, address1, ;  
                 address2, city, state, zipcode , ;
                 homephone, workphone, social, ;
                 birthdate, sex from patfile ;
                 where trim(dob) = ; 
                 trim(thisform.txt_dob.value) ;
                 into CURSOR csrtemp

   CASE ( NOT (isblank(thisform.txt_chart.value)))
          select lname, fname, mname, account, address1, ;
                  address2, city, state, zipcode , ;
                  homephone, workphone, social, ; 
                  birthdate, sex from patfile ;
                  where trim(chart) = ; 
                  trim(thisform.txt_chart.value) ;
                  into CURSOR csrtemp

   OTHERWISE 
      MESSAGEBOX(&quot;Nothing to query&quot;, 6, &quot;Parameters don't qualify&quot;)

ENDCASE

Dave S.
 
Sorry for the incorrect syntax, I was working in JavaScript at the time [purple]

I did post a correction but didn't check to see if it had made it... oh well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top