Microsoft KB Archive/131549

= INFO: Use Place-Holder Commas in Calls with Missing Parameters =

Article ID: 131549

Article Last Modified on 3/3/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q131549



3.00 WINDOWS



SUMMARY
This article shows by example how to pass parameters to functions, procedures, or methods by using place-holder commas for empty values that will take a default value. When you pass nothing, the function receives false (.F.) as the value for that argument.

This Visual FoxPro behavior is different from the behavior of FoxPro version 2.6. In FoxPro version 2.6, you could pass fewer arguments than total number of parameters only if the blank arguments came after the valid (full) arguments.



MORE INFORMATION
In Visual FoxPro version 3.0, you can pass fewer arguments than are requested by a function, method, or procedure by using place-holder commas when you call it.

Code Sample
To demonstrate passing blank parameters, copy the following code into a program file called FOXTEST.PRG and run it:

  *** BEGINNING OF SAMPLE CODE ***

  ***************************************************************** *                        FOXTEST.PRG                           * *  Demonstrates How Visual FoxPro Allows Passing Blank Values  * *        For Parameters Anywhere In the Parameter List         * *                                                              *   *****************************************************************

  SomeDate = mydate(3,4,95) && Pass values for all parameters WAIT WINDOW SomeDate

  SomeDate = mydate(4,,94) && Pass blank values for 2nd parameter WAIT WINDOW SomeDate

  SomeDate = mydate(,4,)   && Pass blank values for 1st and 3rd WAIT WINDOW SomeDate    && parameters

  SomeDate = mydate(,,94)  && Pass blank values for 1st and 2nd WAIT WINDOW SomeDate    && parameters

  SomeDate = mydate(4,,)   && Pass blank values for 2nd and 3rd WAIT WINDOW SomeDate    && parameters (This is the only way FoxPro

&& 2.x allowed blank values to be passed, && at the end of the parameter list only.)

  PROCEDURE MyDate PARAMETERS Month,Day,Year

  * Give each variable a default value for the missing parameters.

  DO CASE

CASE TYPE("Day")="L" lcday="01" CASE TYPE("Day")="N" lcday=ALLTRIM(STR(DAY))

  ENDCASE

  DO CASE

CASE TYPE("Year")="L" lcyear="95" CASE TYPE("Year")="N" lcyear=ALLTRIM(STR(Year))

<pre class="fixed_text">  ENDCASE

<pre class="fixed_text">  DO CASE

CASE TYPE("Month")="L" lcmonth="01" CASE TYPE("Month")="N" lcmonth=ALLTRIM(STR(Month))

<pre class="fixed_text">  ENDCASE

<pre class="fixed_text">  RETURN lcmonth+"/"+lcday+"/"+lcyear

<pre class="fixed_text">  *** End Of Sample Code ***

<div class="references_section">