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

case...endcase or something better

Status
Not open for further replies.

friend01

Programmer
Jun 4, 2009
94
CA
Hi,

I have a brain freeze currently and at a lose on hos to do this. I would think "CASE...ENDCASE" is the best way but I can't for the life of me write the darn code for it. It's pretty simple. Here's my code:

USE MST0910
SCAN FOR amount_rem="3004" AND EMPTY(state)
STORE SUBSTR(tel,1,7) TO t7
STore SUBSTR(tel,1,3) TO t3
SELECT pic_city
SEEK t7
if it's found, sele MST0910 and REPLACE mst0910.state WITH pic_city.prov and move to the next recno() in mst0910. if it's not found, look in a dbf called cell_tel, if it's found in there, sele MST0910 and REPLACE mst0910.state WITH cell_tel.prov and move to the next recno() in mst0910. If it's not found, , using t3 now (not t7) look in a dbf called us_desti, if it's found in there, sele MST0910 and REPLACE mst0910.state WITH us_desti.state. OTHERWISE, just sele MST0910, SKIP.
ENDSCAN

My brain is not working today on how to code that. it must be the snow storm we just got.

Can anybody help me? Please let me know.

Thanks,
F1



ENDSCAN
 
To answer your question -
The code for DO CASE - END CASE is

DO CASE
CASE MYvariable="FIrstchoise"
Take this action
CASE MYvariable="SEcondchoise"
Take this action
etc
etc
OTHERWISE
Take this action
END CASE

The OTHERWISE condition is optional.

DO CASE is kind of a throwback to Foxbase and was used primarily if you had a significant number of choises to sort through.

 
DO CASE is kind of a throwback to Foxbase

Wow!

And I thought that this is one of the most useful switches in FoxPro. Are you suggesting that I throw out all of my DO CASE switches and convert them to a clumsy IF ... THEN ... ELSE format?

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 

Maybe 'Throwback' was a bad choise of terms.

mmerlinn is correct - Do Case/End Case is vastly superior to a collection of nested IF/END IF statements.

 
Try this....

Code:
CLOSE DATABASES ALL
CLEAR ALL
CLEA
SELECT 0
USE C:\Users\johnk\Desktop\srtest\mst0910
SELECT 0
USE F:\DATA\pic_city ORDER npanxx
SELECT 0
USE F:\DATA\cell_tel &&very small dbf
select * from cell_tel where .T. into cursor tmpCell_tel readwrite 
INDEX ON npanxx tag idxcelltel
SELECT 0
USE F:\DATA\us_desti ORDER area

SELECT mst0910
REPLACE frstate WITH state, state WITH "" FOR amount_rem='3004' AND EMPTY(Frstate)

SELECT mst0910
LOCATE 
SCAN FOR amount_rem="3004" AND EMPTY(state)

T7=SUBSTR(tel,1,7)
T3=SUBSTR(tel,1,3)

DO CASE
CASE SEEK(T7, 'PIC_CITY')
REPLACE mst0910.state WITH pic_city.prov
CASE SEEK(T7, 'TMPCELL_TEL')
REPLACE mst0910.state WITH TMPcell_tel.prov
CASE SEEK(T3, 'us_desti')
REPLACE mst0910.state WITH us_desti.state
ENDCASE

ENDSCAN

This is your original done with a DO/CASE... any speed issues would be with the scan on MST0910.

Andy Snyder
SnyAc Software Services Hyperware Inc. a division of AmTech Software
 
Well, if we had

IF / ELSEIF / ELSE / ENDIF
(in some other languages such as VBScript)

then we wouldn't need

DO CASE / CASE / OTHERWISE / ENDCASE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top