Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Scope
Message
 
À
21/04/2001 11:32:38
Ben Dekker
Dekker Soft & Hardware
Axel, Pays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: Scope
Divers
Thread ID:
00497534
Message ID:
00498289
Vues:
13
>Hi Mark
>
>
>Can you help me once more?
>I want to make a function:
>
>FUNCTION SCOPE (cDbf,cField,xStart,xEnd)
>select (cDbf)
>set filter to between((cField), xStart, xEind)
>ENDFUNC
>
>This function is not working, I'm doing something wrong.
>I want to try to make a function call something like this.
>
>
>scope("year","date", {^2001-01-01}, {^2001-30-01})
>
>
>Your tree lines of code is wroking fine, but i prefer to
>make functions in my code so i can make a lib.

The problem is that the variables involved go out of scope when you leave the function. To do what you want it to do just change it to be macro substitution.
FUNCTION SCOPE (cDbf,cField,xStart,xEnd)
LOCAL lcFilterString
SELECT (cDbf)
DO CASE

   CASE TYPE("xStart") = "D"
      lcFilterString = "set filter to between("+cField+",{"+DTOC(xStart)+"},{"+DTOC(xEnd)+"})"
   CASE TYPE("xStart") = "C"
      lcFilterString = "set filter to between("+cField+",'"+xStart+"','"+xEnd+"')"
   CASE TYPE("xStart") = "N" OR TYPE("xStart") = "I"
      lcFilterString = "set filter to between("+cField+","+xStart+","+xEnd+")"
ENDCASE
*-- Set the filter on selected table
&lcFilterString
ENDFUNC
The call to the routine stays the same. The only requirement is that both variables to check must be of the same type. You might want to add more checking, I assumed you might want to use it for more than just filtering on date fields.
Cy Welch
Senior Programmer/Analyst
MetSYS Inc
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform