Page 1 of 1 1
Topic Options
#134488 - 2005-02-24 04:09 PM Call a sub
alexchevrier Offline
Fresh Scripter

Registered: 2002-11-11
Posts: 15
Loc: Quebec
Moderators note: Thread moved to General Discussions. Original author may resubmit the suggestion, if after discussion, it is still desired.
I suggest a command to call a sub in a different file. I use many kix files on different domains, but often sub-routines are identical and I must modify them in every files when I change something.

With a file containning all the subs, I would just have to copy this file on every domains instead of modifying it on every domains.


Edited by Les (2005-02-24 08:07 PM)

Top
#134489 - 2005-02-24 05:11 PM Re: Call a sub
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
You are talking about kix's UDF? or actual GOSUB's

If you are using UDF's you can keep all of your UDF's in a centeral file and load those UDF's by using the CALL "UDFFile.kix"

any code in "UDFFile.kix" will be executed, but as long as this file only contains UDF's, the UDF's will be loaded into memory and can then be executed.

If you are using gosub's.... i would move over to a UDF format my self.


Top
#134490 - 2005-02-24 06:43 PM Re: Call a sub
alexchevrier Offline
Fresh Scripter

Registered: 2002-11-11
Posts: 15
Loc: Quebec
What is UDF ?
Top
#134491 - 2005-02-24 07:05 PM Re: Call a sub
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
User Defined Function is explained in the manual.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134492 - 2005-02-24 07:24 PM Re: Call a sub
alexchevrier Offline
Fresh Scripter

Registered: 2002-11-11
Posts: 15
Loc: Quebec
All I see in the manual is the Function... and it doesn't seem to be able to do what I want to, which is regroup all my subs (or functions) in a single file so that when I modify one sub, I can simply copy it in every netlogon folder instead of modifying every files.

I'll give an exemple... Let's say a create a file called subs-funtions.kix, which contains sub1 and sub2. From my main kix file, I would like to be able to do something like this : call "subs-functions.kix, sub1".

Is UDF able to do that ?

Top
#134493 - 2005-02-24 07:29 PM Re: Call a sub
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Subs are "old school" spaghetti code. UDFs are "new school" modular code. UDFs can be centrally managed and called. This is explained in the manual, in our FAQ forum, and discussed at great length in the other forums.

Your suggestion has been noted. If you wish to discuss alternatives like UDFs further, please post in the General Discussions forum.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134494 - 2005-02-24 07:40 PM Re: Call a sub
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
les: move this thread to general please.

alexchevrier:

here is an example.

using gosubs... what you have now with everythign in one file.
Code:

? "starting a GOSUB now!"
gosub "sub1"
? "THE Gosub is finished."

exit 0


:sub1
? "the SUB1 is now running"
return





now here is an example of using UDF's (User Defined Function)


this is your main script
Code:

call 'functions.kix'

? "starting Function1"
Function1
? "Function1 is finished"



and here is Functions.kix

Code:

Function Function1
? "Running Function1!"
endfunction

Function Function2
? "Running Function2!"
endfunction




Top
#134495 - 2005-02-25 11:12 AM Re: Call a sub
Richard H. Administrator Offline
Administrator
*****

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


I'll give an exemple... Let's say a create a file called subs-funtions.kix, which contains sub1 and sub2. From my main kix file, I would like to be able to do something like this : call "subs-functions.kix, sub1".

Is UDF able to do that ?




Yes, it is - in fact it is superior to the method that you are suggesting.

Convert all your sub-routines to UDFs using Function/EndFunction and store in your file "subs-functions.kix"

At the start of your script, "CALL subs-functions.kix". This won't execute any code, but it will load your functions into memory ready to be executed when needed.

Now in your script you can call sub1() sub2() whenever you like because they have been loaded in memory - you don't need to call the "subs-functions.kix" file again.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

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

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org