Page 1 of 1 1
Topic Options
#77744 - 2001-05-04 05:41 AM More weird thing with execute() inside a function
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I stumbled upon this...

first the code

code:

$a = "test"
$string = "this is a string with ~$$a~ in it"


; this is just filler to get to the function....
;
if instr($string,"~") <> 0
? FillVariable($string)
else
? $String
endif

exit

; This is a function that will look for $variables inside a
; string, and fill them with their values, for the moment, I
; am just trying to fill the variable.
Function FillVariable($string)

DIM $string, $element ;<---this line is playing a major part in the weirdness!

$string = split($string,"~")
for each $element in $string
if substr($element,1,1) = "$"
$nul = execute('$$trap = $element ? "in execute $$$$trap = $$trap"')
? "Outside of execute $$trap = " + $trap
endif
next
endfunction


Everything is working fine with the above code... but since i want to my variables used inside a function, to stay inside the function. I do a DIM of all of the variables that the function uses.

But if i change this line

code:

DIM $string, $element ;<---this line is playing a major part in the weirdness!

to this

code:

DIM $string, $element, $trap ;<---this line is playing a major part in the weirdness!

the variable $trap never makes it out of the EXECUTE() command.

[edit]

It appears that any variable defined in an execute() command is defined as a global variable. Shouldn't variables restricted to a subroutine with a DIM command stay with in that subroutine? This is why when i DIM $trap inside the function, and then i do an EXECUTE() with $trap, $trap new value is set at the GLOBAL level, not at the calling DIMed level (does that make any sense?)

Bryce


------------------
kix.isorg.net

[This message has been edited by Bryce (edited 04 May 2001).]

Top
#77745 - 2001-05-04 05:57 AM Re: More weird thing with execute() inside a function
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
DOH!!! (50 lashes with a wet noodle!!!)

I was Using Beta1.... my bad .....

Everything works great!!!!

------------------
kix.isorg.net

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 593 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.147 seconds in which 0.084 seconds were spent on a total of 12 queries. Zlib compression enabled.