Visit our new web pagesWe have launched a new extended set of web pages at www.alvechurchdata.co.uk. These old pages will stay on the server because people still have links to them but they will not be updated. The new version of this page is at www.alvechurchdata.co.uk/hints-and-tips/fox101case.html. |
||
Home About us Development Training Support |
VFP Tutorial - Do CaseAllows a choice between several actions:
Do Case
Case _TALLY = 0 Wait Window 'No records found' Case _TALLY = 1 Wait Window 'One record found' Otherwise Wait Window 'Many records found' EndCase Each Case statement is followed by an expression which must evaluate to true or false. FoxPro evaluates each of these in sequence. If the expression following the first Case statement evaluates as true (.T. in FoxPro) then the statements between this Case and the next one will be executed. The rest of the structure will be skipped and execution will continue on the line following the EndCase statement. If the first expression evaluates as false (.F. in FoxPro) then the next Case statements will be evaluated in turn until one is found to be true. If none are found to be true then the code following Otherwise will be executed. Notes_TALLY is a variable maintained by FoxPro which holds the number of records processed by the last command. The condition must evaluate as .T. or .F. because the logical values in FoxPro are a separate data type and an integer result will not be interpreted as a logical value. Be careful when designing a Case and remember that the expressions are evaluated in sequence. If you need to test whether something is greater than 1 or greater than 10 then you must test for greater than 10 first. If you test for greater than 1 first then a value such as 11 will satisfy that condition and the greater than 10 test will not be reached. The Otherwise clause is optional. If it is not included and all the individual Case statements evaluate as false then none of the code will be executed. Each Case can have an expression based on a different variable. This example works out the method of delivery from the value of the order, the weight of the goods and the country it has to be delivered to.
Do Case
Case lyCost > 1000 *-- Free delivery for large orders lcDelMethod = 'Free' Case lnWeight > 10 *-- Buyers must collect cheap, heavy orders lcDelMethod = 'Collect' Case lcCountry <> 'UK' *-- Airmail for a light, cheap, overseas delivery lcDelMethod = 'Airmail' Otherwise *-- Must be light, cheap, inland delivery lcDelMethod = '2nd class mail' EndCase Back to FoxPro program control . Introduction | Environment | Project | Tables | Forms | Navigation | Executable |
Hints & tips
The textbox class in Visual FoxPro 9 has a new Autocomplete
property which shows the user the previous values that have
been entered in that textbox.
More...
|