PASS THE ADDRESS AS PARAMETER 
Author Message
 PASS THE ADDRESS AS PARAMETER
Hi, are there anyway that I can change content of the variables in a function
routine when I passed these variables as parameter? Another word can I pass
the address of these variables to a function and change the content of the
address. I know you probably will tell me that declared these variables
globaly, let say that we both don't want to do that.


Fri, 11 Jul 1997 22:10:43 GMT
 PASS THE ADDRESS AS PARAMETER



Quote:
>Hi, are there anyway that I can change content of the variables in a function
>routine when I passed these variables as parameter? Another word can I pass
>the address of these variables to a function and change the content of the
>address. I know you probably will tell me that declared these variables
>globaly, let say that we both don't want to do that.

Try:

SET UDFPARMS TO REFERENCE

This will let you pass parameters to UDFS by reference.  Likewise, you
could simply use a procedure instead of a function, since procedure
parameters are always passed by reference.

-Julien

--
-----------------------------------------------------------------------------
Julien Sellgren                              University of British Columbia

-----------------------------------------------------------------------------



Sat, 12 Jul 1997 01:17:38 GMT
 PASS THE ADDRESS AS PARAMETER

Quote:
>Hi, are there anyway that I can change content of the variables in a function
>routine when I passed these variables as parameter? Another word can I pass
>the address of these variables to a function and change the content of the
>address. I know you probably will tell me that declared these variables
>globaly, let say that we both don't want to do that.

Without getting into a bunch of variable scoping issues, all you need to

Example:

val = 1

? val

PROCEDURE ChangeVal
PARAMETER ValueIn
ValueIn = 2
RETURN

- John
--
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------



Sat, 12 Jul 1997 01:42:45 GMT
 PASS THE ADDRESS AS PARAMETER

Quote:

> Hi, are there anyway that I can change content of the variables in a function
> routine when I passed these variables as parameter? Another word can I pass
> the address of these variables to a function and change the content of the
> address. I know you probably will tell me that declared these variables
> globaly, let say that we both don't want to do that.

Oh, I wouldnt dare tell you to declare variables global :-)
1. If you are using procedures rather than functions (and some discussion
in this group and elsewhere seems to have shown that they are basically
the same, except for the mode of calling) then all variables are passed by
reference and are modifiable in the procedure.
2. If you are calling functions (i.e. as in =afunc(5) instead of DO afunc WITH 5)
then how the variables are passed depends on SET UDFPARMS. The default
is SET UDFPARMS TO VALUE, i.e. UDF parameters are passed by value. If you
SET UDFPARMS TO REFERENCE then UDF parameters will be passed by reference.
3. You can force passing by reference even if SET UDFPARMS TO VALUE by including


the value of the first array element will be passed. You cannot pass arrays
by value (hey, perhaps this will be one of the really useful things in VFP :-)

Alex Baxter, ACST



Mon, 14 Jul 1997 19:30:00 GMT
 PASS THE ADDRESS AS PARAMETER

Quote:

> Hi, are there anyway that I can change content of the variables in a function
> routine when I passed these variables as parameter? Another word can I pass
> the address of these variables to a function and change the content of the
> address. I know you probably will tell me that declared these variables
> globaly, let say that we both don't want to do that.

I think I know what you are asking.  Here's the way things are normally:

y=ADD(a,b)

FUNCTION add
PARAMETERS i,j
RETURN i+j

You want to be able to modify one of the variables directly.  lets
say, for example, that after adding, you want to clear the variables
(store 0 in them).

Try this:


FUNCTION add
PARAMETERS i,j
PRIVATE res
res=i+j
i=0
j=0
RETURN res

When you return from this function, a & b with both be 0.



Tue, 15 Jul 1997 00:05:57 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. Pass-Through Queries from Access - How to pass form-based parameters

2. How to pass pass parameters to the IN clause

3. Passing Parameters down to a buried view or stored procedure using parameters

4. Passing multiple parameters for a parameter using temporary stored procedures

5. passing parameter to a parameter query

6. passing optional parameters to the parameters collection

7. Passing Parameters to stored parameter queries using VB 5's Data Controls

8. How to pass multi parameters in ado command parameter

9. Passing IP address to sql server via SQL XML

10. TNS:illegal Address parameter error while connectin to server

11. Passing parameters to sp

12. Passing a parameter to a stored procedure


 
Powered by phpBB® Forum Software