#153121 - 2005-12-08 08:13 PM
Re: Just for the record
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Hmmm I thought the new KiX versions would tell you right away what the issue is.
Using these values works well for me.
Code:
Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('NoMacrosInStrings','On')
|
|
Top
|
|
|
|
#153123 - 2005-12-08 08:32 PM
Re: Just for the record
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Quote:
The action of DIMing the variable makes its value NULL(Is that right?)
Thats right.
Quote:
If I pass a parameter like I did above, does the script consider it dimmed?
Yes and no. It considers it as GLOBAL, as if you had done this:
Global $somevariable
Quote:
If not how do I DIM it without losing its contents?
As far as I know you cant. Just assume command line $vars are Global.
|
|
Top
|
|
|
|
#153126 - 2005-12-08 08:39 PM
Re: Just for the record
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Not to hammer this home any futher, but the following clearly demonstrates this behavior:
Code:
Break On
$= SetOption("Explicit", "On")
?"value=" $somevariable
Exit 0
We first set Explicit ON, which means this:
Quote:
When you enable the Explicit option, you must explicitly declare all variables using Dim, Global or ReDim statements. If you attempt to use an undeclared variable name, an error occurs. Use the Explicit option to avoid incorrectly typing the name of an existing variable.
Then if you run the script like this:
C:\> kix32 test.kix
You get this:
ERROR : undefined variable [somevariable]! Script: E:\t.KIX Line : 7
But then if you run the same script like this:
C:\> kix32 test.kix $somevariable=1
You get no syntax error. $somevariable passes the test as being declared (Global in this case).
-Shawn
|
|
Top
|
|
|
|
#153128 - 2005-12-08 11:23 PM
Re: Just for the record
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
Stanley... you know I thought you were talking about passing variables to a UDF rather than a script. I'm glad you posted this as I'm sure this would have bitten me at some point too.
At one point when I first started using Explicit/DIM, I thought I had to dim the variables in the UDF header within the function, ie... Code:
function($var1,$var2) dim $var1,$var2 ;... endfunction
Interestingly it works, but I believe it was Jooel, who smacked me around a bit and told me it only worked because Kix was so forgiving. So try not to make that mistake.
|
|
Top
|
|
|
|
#153131 - 2005-12-12 10:27 AM
Re: Just for the record
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
hmmm... glenn, doesn't your code actually force kixtart to end processing if not declared? you can't test $CL_ARG as explicit says you haven't declared it and bombs out.
Did you try it? I guess not 
I use the same trick.
IsDeclared() has special processing which means that the script does not abort if the variable is undeclared. Just as importantly, checking if the variable exists does not create it implicitly.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|