Page 1 of 1 1
Topic Options
#137650 - 2005-04-11 12:15 AM Using vars and macros in Include statements
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
You cannot use variables, macros and env-strings in Include statemenent,

You can beat this limitation, by using Execute()

Try placing this small script in @LanRoot (Normally: %WinDir%\System32)
Name it: Test.inc
Code:
Function IncOk()
Dim $x
'I am here !!'
Get $x
EndFunction


Then try executing this script
Code:

$RC = Execute("Include '@LanRoot\Test.inc'")
IncOk()



Seems to work

I just tried:
Code:
Execute("Include '@LServer\Netlogon\KiX\InstProg.udf'")



And then called a function in InstProg.udf

Also worked OK

-Erik


Edited by kholm (2005-04-11 12:38 AM)

Top
#137651 - 2005-04-11 12:40 AM Re: Using vars and macros in Include statements
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... IMHO, that is a dumb idea. WHat is the point of that? May as well stick with CALL!

If you tokenize the script, the Execute() won't execute and the included script won't be included.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137652 - 2005-04-11 12:54 AM Re: Using vars and macros in Include statements
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Not true Les,

I just tokenized the script, the Execute() part still works.

-Erik

Top
#137653 - 2005-04-11 12:56 AM Re: Using vars and macros in Include statements
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You missed the point. I did not say Execute() would not work, I meant it would not execute at tokenizing so the file would not be included in the tokenized file.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137654 - 2005-04-11 01:16 AM Re: Using vars and macros in Include statements
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Right Les,

I forgot to delete/rename the test.inc file.

So no beating the vars/macros in Include

-Erik

Top
#137655 - 2005-04-11 01:21 AM Re: Using vars and macros in Include statements
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... if you really want to beat this, you can. Just write some KiX generating code in a wrapper script that will build a KiX script with your include lines.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137656 - 2005-04-11 01:35 AM Re: Using vars and macros in Include statements
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Well, I have had the same thoughts (KiX generating code), but it wouldn't work for ie. @LServer, @UserID ...

-Erik

Top
#137657 - 2005-04-11 09:53 AM Re: Using vars and macros in Include statements
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Well, I have had the same thoughts (KiX generating code), but it wouldn't work for ie. @LServer, @UserID ...

-Erik




But those sort of variables don't make any sense in this context.

INCLUDE is a "tokenisation time" directive, not a run-time directive.

The files are included at the point in time that you tokenise the script, not when it is run, so @LSERVER and @USERID will be set to the value of the environment doing the tokenisation, not the value of the environment that it is going to run in.

This means that a wrapper which expand include lines is entirely feasible. However it would be better to use a mechanism designed for managing software project files.

Top
#137658 - 2005-04-12 08:09 PM Re: Using vars and macros in Include statements
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
Bingo! Richard is through to the next round of KiXtart Trivia: this is exactly why INCLUDE works the way it does.


Top
#137659 - 2005-04-13 01:03 AM Re: Using vars and macros in Include statements
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Ruud/Richard

Have I missed something ?

As I read Your posts, this would lead to 'macos are not allowed in include files'.

If this is the case shouldn't KiX deny a script containing macros to be included ?

-Erik

Top
#137660 - 2005-04-13 01:25 AM Re: Using vars and macros in Include statements
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
No, no, no: INCLUDEd scripts can contain any valid KiXtart code. The INCLUDE *statement* itself just takes a single, flat string as its argument.

So:
INCLUDE @LSERVER + "\NETLOGON\SOMESCRIPT.KIX"
is incorrect, and
INCLUDE "\\SOMESERVER\NETLOGON\SOMESCRIPT.KIX"
is correct.

Ruud

Top
#137661 - 2005-04-14 12:00 AM Re: Using vars and macros in Include statements
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Thanks Ruud for the clarifikation.

And Les, Your KiX generating code makes more sense to me now. I would in all cases make a script to to transform the scripts to ensure that
I have kept the 'source' scripts invisible to the users.

Thank You both.

-Erik

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
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

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