Why is Public MemVAR unavailable during procedure call?

My program calls a procedure with a parameter split, which is just a
memory variable containing and email address with or WITHOUT the word
"Email" (which gives me a clue which web site it came from).

Do Email with split

**********
The actual procedure called (Email) is below and the problem : is at
the very bottom of the code where the procedure crashes because it
says the Public MemVariable split does not exist.
**********

PROCEDURE Email
parameters pmail
pmail=strtran(lower(strtran(strtran(strtran(pmail,"mailto",""),"
",""),":","")),"email","")
Do Case
Case empty(remail)
repl remail with pmail
Case pmail $remail
do bOhh
Wait
Wait Window pmail+" ALREADY in remail" timeout 3
Case alltrim(remail) $pmail
repl remail with pmail
Case len(pmail+" "+trim(remail2nd))<=Fsize('remail2nd')
repl remail2nd with pmail+" "+trim(remail2nd)
Case len(pmail+" "+trim(remail))<=Fsize('remail')
repl remail with pmail+" "+trim(remail)
Otherwise
do bUhOh
_cliptext=pmail
wait
wait window " pmail =>_cliptext to BIG CTRL+V to paste " + _cliptext
EndCase
********************************HERE IS THE PROBLEM***************
If "EMAIL" $upper(split) && crashes says there is no memvar split
Do RSX with "W"
Else
Do RSX
Endif

This is weird, the memvar split is PUBLIC, I can go to the command
prompt and type in
? Split
and I can see its contents.

What gives?
John "J.J." Jackson

Re: Why is Public MemVAR unavailable during procedure call? by Cyrus

Cyrus
Sat Mar 26 19:05:46 CST 2005

JJ wrote:
> Why is Public MemVAR unavailable during procedure call?
>
> My program calls a procedure with a parameter split, which is just a
> memory variable containing and email address with or WITHOUT the word
> "Email" (which gives me a clue which web site it came from).
>
> Do Email with split
>
> **********
> The actual procedure called (Email) is below and the problem : is at
> the very bottom of the code where the procedure crashes because it
> says the Public MemVariable split does not exist.
> **********
>
> PROCEDURE Email
> parameters pmail
> pmail=strtran(lower(strtran(strtran(strtran(pmail,"mailto",""),"
> ",""),":","")),"email","")
> Do Case
> Case empty(remail)
> repl remail with pmail
> Case pmail $remail
> do bOhh
> Wait
> Wait Window pmail+" ALREADY in remail" timeout 3
> Case alltrim(remail) $pmail
> repl remail with pmail
> Case len(pmail+" "+trim(remail2nd))<=Fsize('remail2nd')
> repl remail2nd with pmail+" "+trim(remail2nd)
> Case len(pmail+" "+trim(remail))<=Fsize('remail')
> repl remail with pmail+" "+trim(remail)
> Otherwise
> do bUhOh
> _cliptext=pmail
> wait
> wait window " pmail =>_cliptext to BIG CTRL+V to paste " + _cliptext
> EndCase
> ********************************HERE IS THE PROBLEM***************
> If "EMAIL" $upper(split) && crashes says there is no memvar split
> Do RSX with "W"
> Else
> Do RSX
> Endif
>
> This is weird, the memvar split is PUBLIC, I can go to the command
> prompt and type in
> ? Split
> and I can see its contents.
>
> What gives?
> John "J.J." Jackson
For starters, you should use the variable pmail since you have passed it
to the procedure anyways. That should certainly do that. I seem to
recall having seen a problem like that once with passing a public
variable to a method and it couldn't see it and worked if I either
didn't pass it as a parameter or if I used the parameter. And of
course, why pass it as a parameter if your not going to use it? That
destroys it's ability to act a a black box since you are making it
depend on a variable existing. Either use the variabe you passed it to,
or don't pass it. That should make it work properly.

--
Cy Welch
Senior Programmer
MetSYS Inc
http://www.metsysinc.com

Re: Why is Public MemVAR unavailable during procedure call? by Bernhard

Bernhard
Mon Mar 28 08:20:32 CST 2005

Hi JJ
> Why is Public MemVAR unavailable during procedure call?
This is normal (and very old) behaviour of Foxpro. If you pass a variable as
parameter then the original variable is hidden in the procedure. This is in
effect with public and private variables. Imho it is somehow related to "call by
reference".

You can keep it visible if you put an expression as parameter:

Do email with split + ""

Now, the public (or private) variable split is visible in your procedure.

Regards
Bernhard Sander

Re: Why is Public MemVAR unavailable during procedure call? by Dennis

Dennis
Mon Mar 28 12:13:00 CST 2005

Bernhard,

"Bernhard Sander" <fuchs@individsoft.de> wrote in message
news:epMSMF6MFHA.3928@TK2MSFTNGP09.phx.gbl...
> Hi JJ
> > Why is Public MemVAR unavailable during procedure call?
> This is normal (and very old) behaviour of Foxpro. If you pass a variable
as
> parameter then the original variable is hidden in the procedure. This is
in
> effect with public and private variables. Imho it is somehow related to
"call by
> reference".
>

No need to be humble. You are correct. I just ran a test in a program in
which I declared a public variable, gcVar, and stored a character value in
it. When I passed it to a procedure by reference, VARTYPE(gcVar) returned
"U" inside the procedure, but when it was passed by value, VARTYPE(gcVar)
returned "C".

By the way, I would expect this behavior and here's why.

When passing a variable by reference to a procedure, you are passing its
memory location to the procedure with implication the procedure can change
the value of the variable passed. The procedure does not need to know the
name of the variable because you have passed its memory location to it as an
argument to one of its parameters thus it can change the value of the
parameter which will change to value of the variable.

For example:

PUBLIC gcVar
gcVar = "Test"

MyProc(gcVar) && passed by value

?gcVar && prints "Test"

MyProc(@gcVar) && passed by reference

?gcVar && prints "New"

RELEASE gcVar

PROCEDURE MyProc

LPARAMETERS tcParm

tcParm = "New"

ENDPROC

Finally, this very old behavior does not just apply to FoxPro, but applies
to all programming languages that I have used or studied in the past.

Hope that helps,



Re: Why is Public MemVAR unavailable during procedure call? by Fernando

Fernando
Tue Mar 29 12:40:12 CST 2005

This occurs when the "split" variable is passed by reference in this way:

Do Email with split && "split" is passed by reference.

If you needn't to alter the "split" value inside the procedure, you should
do the call in this way:

Do Email with (split) && "split" is passed by value.

...or just use the "pmail" parameter who receives the "split" variable
inside the procedure.


Regards,

Fernando D. Bozzo
VFP6/SP5
Madrid/Spain


"JJ" <jjyg@adelphia.net> escribió en el mensaje
news:m4rb419ivplfm4drpnljcaoern2fmhdcsi@4ax.com...
> Why is Public MemVAR unavailable during procedure call?
>
> My program calls a procedure with a parameter split, which is just a
> memory variable containing and email address with or WITHOUT the word
> "Email" (which gives me a clue which web site it came from).
>
> Do Email with split
>
> **********
> The actual procedure called (Email) is below and the problem : is at
> the very bottom of the code where the procedure crashes because it
> says the Public MemVariable split does not exist.
> **********
>
> PROCEDURE Email
> parameters pmail
> pmail=strtran(lower(strtran(strtran(strtran(pmail,"mailto",""),"
> ",""),":","")),"email","")
> Do Case
> Case empty(remail)
> repl remail with pmail
> Case pmail $remail
> do bOhh
> Wait
> Wait Window pmail+" ALREADY in remail" timeout 3
> Case alltrim(remail) $pmail
> repl remail with pmail
> Case len(pmail+" "+trim(remail2nd))<=Fsize('remail2nd')
> repl remail2nd with pmail+" "+trim(remail2nd)
> Case len(pmail+" "+trim(remail))<=Fsize('remail')
> repl remail with pmail+" "+trim(remail)
> Otherwise
> do bUhOh
> _cliptext=pmail
> wait
> wait window " pmail =>_cliptext to BIG CTRL+V to paste " + _cliptext
> EndCase
> ********************************HERE IS THE PROBLEM***************
> If "EMAIL" $upper(split) && crashes says there is no memvar split
> Do RSX with "W"
> Else
> Do RSX
> Endif
>
> This is weird, the memvar split is PUBLIC, I can go to the command
> prompt and type in
> ? Split
> and I can see its contents.
>
> What gives?
> John "J.J." Jackson



Re: Why is Public MemVAR unavailable during procedure call? by Fernando

Fernando
Tue Mar 29 12:47:07 CST 2005

One more thing:

If you suspend the program when the error occurs and do DISPLAY MEMORY LIKE
*, you should see your split variable with a (hid)den indicator on the
right, who tells you that the variable exists, but is hidden for the actual
procedure.



Re: Why is Public MemVAR unavailable during procedure call? by JJ

JJ
Tue Mar 29 16:43:20 CST 2005

Cyrus Welch <cywelch@hotmail.com> wrote:

>For starters, you should use the variable pmail since you have passed it
>to the procedure anyways.

I can't. What this procedure DOES is strip out anything but the email
address itself so it can be inserted in to my table. One of the things
that is stripped as the procedure runs is the word "EMAIL"

So as the procedure runs the Word EMAIL will disappear. It still
exists in the originally passed parameter though (the value of STRIP)

HOWEVER, this email address could have come from a number of different
websites and I use the field Recsource to accumulate the different
places I got information from for this individual.

Another Procedure RSX handles that for me.

Hence

> ********************************HERE IS THE PROBLEM***************
> If "EMAIL" $upper(split) && crashes says there is no memvar split
> Do RSX with "W"
> Else
> Do RSX
> Endif

I think what I need to do is use another memory variable in the
procedure to do my email address strip down, i.e. not modify the
contents of plast itself, let it remain equal to split.

John "J.J." Jackson

Re: Why is Public MemVAR unavailable during procedure call? by Gene

Gene
Tue Mar 29 17:26:20 CST 2005

On Tue, 29 Mar 2005 17:43:20 -0500, JJ <jjyg@adelphia.net> wrote:

>Cyrus Welch <cywelch@hotmail.com> wrote:
>
>>For starters, you should use the variable pmail since you have passed it
>>to the procedure anyways.
>
>I can't. What this procedure DOES is strip out anything but the email
>address itself so it can be inserted in to my table. One of the things
>that is stripped as the procedure runs is the word "EMAIL"

[snip]

>I think what I need to do is use another memory variable in the
>procedure to do my email address strip down, i.e. not modify the
>contents of plast itself, let it remain equal to split.

Exactly.

Sincerely,

Gene Wirchenko