Jochen
|
(KiX Supporter)
|
2001-04-17 09:05 AM
|
|
|
|
|
#Include ?
|
|
How about an Include "path" statement for UDF's ???Jochen
|
|
Re: #Include ?
|
|
And how about a #path statment where we can specify the path to the external files. I know we can easily enough create and use a $path variable but I like the uniformity afforded by such things as #include and #path.
|
kholm
|
(Korg Regular)
|
2001-05-03 12:25 AM
|
|
|
|
|
Re: #Include ?
|
|
JochenI think that Bryce has just discovered the 'include' option. If you call a script containing only functions, these functions will be available in the rest of the script, including other scripts called later from the main script. Have a look at Bryce's script: Modular Logon Script Suggestion to Ruud, make an alias for CALL, called Include, just for the clarity when reading scripts, so: Include Script Would execute the same code as: Call Script Erik
|
cj
|
(MM club member)
|
2001-05-03 01:32 AM
|
|
|
|
|
Re: #Include ?
|
|
try this $include="call" ; hide this in the script somewhere obscure where you will forget about it then somewhere obvious: $=execute("$INCLUDE myfunctions.k2k") cj
|
kholm
|
(Korg Regular)
|
2001-05-08 12:50 AM
|
|
|
|
|
Re: #Include ?
|
|
Making an include library for functionsOne way of implementing an include library for functions could be: Set the environmentvariable %KixInclude%, either in Autoexec.bat, via your logon script or via adding the line: SetL "KixInclude=C:\KixInclude\" in the master script %KixInclude% must end with "\" or be empty to make this example work. Example of using this: UseDate.kix code:
Break On ;#INCLUDE DateFunc, next line loads all Functions in DateFunc.kix for global use Call "%KixInclude%DateFunc.kix" ; If You have set the environment variable %KixInclude% to point to the Library containing your ; 'INCLUDE' library, DateFunc will be called from there, otherwise, must exist in current directory. ; Using Functions from DateFunc.kix: ; Date 30 days ago $Date = CvtDate(IntDate(@Date) - 30) ? "Date 30 days ago: " + $Date ; Dayname for Date 30 days ago ? "Dayname for " + $Date + " is " + DayName($Date) ; Age of Win.ini in days $FileDate = SubStr(GetFileTime(%WINDIR% + "\Win.ini"), 1, 10) ? "Age of " + %WINDIR% + "\Win.ini in days is: " + (IntDate(@Date) - IntDate($FileDate)) ? "Pause " Get $x
Include library: DateFunc.kixcode:
; #INCLUDE Library of functions for date conversions; The algorithms for used here is taken directly from here: ; http://www.capecod.net/~pbaum/date/date0.htm ; URL found by rhowarth: http://kixtart.org/board/Forum2/HTML/000572.html ; Explanation of Rata Die format: ; http://www.capecod.net/~pbaum/date/rata.htm ; Only valid for Gregorian dates, dates after: October 15, 1582 ; Requires: MathFunc ;Wish : Function UdfLoaded to check if an UDF is already loaded ;#INCLUDE ;If Not UdfLoaded("Mod") ; Call %KixInclude% + "MathFunc.kix" ;EndIf Function CvtDate($RataDie) ; Convert a date from Rata Die to Calendar format. ; The Algorithm used here is taken from here: http://www.capecod.net/~pbaum/date/inratimp.htm ; Input ; Integer (Rata Die) greater than zero ; Returns ; Date on format 'YYYY/MM/DD' ; On Error returns 0 If VarType($RataDie) <> 2 And VarType($RataDie) <> 3 $CvtDate = 0 Return EndIf Dim $Z,$H,$A,$B,$C,$Year,$Month,$Day $Z = $RataDie + 306 $H = 100 * $Z - 25 $A = $H / 3652425 $B = $A - $A / 4 $year = (100 * $B + $H) / 36525 $C = $B + $Z - 365 * $Year - $Year / 4 $Month = (5 * $C + 456) / 153 $Day = $C - (153 * $Month - 457) / 5 If $Month > 12 $Year = "" + ($Year + 1) $Month = "" + ($Month - 12) Else $Year = "" + $Year $Month = "" + $Month EndIf While Len($Year) < 4 $Year = "0" + $Year Loop While Len($Month) < 2 $Month = "0" + $Month Loop $Day = "" + $Day While Len($Day) < 2 $Day = "0" + $Day Loop $CvtDate = $Year + "/" + $Month + "/" + $Day EndFunction Function DayName($Date) ; Convert a date from Calendar to dayname. ; If dayname for today is wanted, use macro @Day instead ; Input ; String: Date on format 'YYYY/MM/DD' ; Returns ; String = DayName ; On Error returns 0 If Not IsDate($Date) $DayName = 0 Return EndIf $WeekDayName = Split("Sunday Monday Tuesday Wednesday Thursday Friday Saturday") $DayName = $WeekDayName[Mod(IntDate($Date), 7)] EndFunction Function IntDate($Date) ; Convert a date from Calendar to Rata Die (Integer) format. ; The Algorithm used here is taken from here: http://www.capecod.net/~pbaum/date/rataimp.htm ; Input ; String: Date on format 'YYYY/MM/DD' ; Returns ; Integer (Rata Die) greater than zero ; On Error returns 0 If Not IsDate($Date) $IntDate = 0 Return EndIf Dim $Year,$Month,$Day $Year = Val(SubStr("$Date", 1, 4)) $Month = Val(SubStr("$Date", 6, 2)) $Day = Val(SubStr("$Date", 9, 2)) If $Month < 3 $Month = $Month + 12 $Year = $Year - 1 EndIf $IntDate = $Day + (153 * $Month - 457) / 5 + 365 * $Year + $Year / 4 - $Year / 100 + $Year / 400 - 306 EndFunction Function IsDate($Date) ; Check if inputstring is a string on format 'YYYY/MM/DD' ; Input ; String ; Returns ; Integer -1 if it is correct format and date is valid (Month < 13 and Days in month valid - checked for Leap year) ; On Error returns 0 $IsDate = 0 If VarType($Date) <> 8 ; Not a string Return EndIf If Len($Date) <> 10 Return EndIf Dim $Numbers, $i, $Cif $Numbers = "0123456789" For $i = 1 To 10 $Cif = SubStr($Date, $i, 1) Select Case $i = 5 Or $i = 8 If $Cif <> "/" Return EndIf Case "Else" If Not InStr($Numbers, $Cif) Return EndIf EndSelect Next Dim $Year,$Month,$Day $Year = Val(SubStr($Date, 1, 4)) $Month = Val(SubStr($Date, 6, 2)) If $Month > 12 Return EndIf $DaysInMonth = Split("0 31 28 31 30 31 30 31 31 30 31 30 31") If $Month = 2 ; Check for Leap year If Mod($Year, 4) = 0 ; Could be Leap year If Not (Mod($Year, 100) = 0 And Mod($Year, 400)) ; Century is NOT Leap year, Except Mod(Century, 4) = 0 $DaysInMonth[2] = "29" EndIf EndIf EndIf $Day = Val(SubStr($Date, 9, 2)) If $Day > Val($DaysInMonth[$Month]) Return EndIf $IsDate = -1 EndFunction ; Should not be here if function: UdfLoaded() or something similar is 'invented' in KiX2001 Function Mod($Dividend, $Divisor) ;Modulus Function Should be located in FuncLib: MathFunc.kix, See Wish: UdfLoaded() $Mod = $Dividend - ($Dividend / $Divisor) * $Divisor endfunction Return ; Functions loaded
I call back my previous post on this topic, because Scripts used as include scripts for functions should only contain functions, and ought to end with a return statement, this would make an Include command forced to check for this, adding more complexity to KiX32.exe. If my new wish: (UdfLoaded), comes true, an UDF library could also start with something like: ; #IfInclude "MathFunc.kix" If Not UdfLoaded("Mod") Call %KixInclude% + "MathFunc.kix" EndIf You could use cj's suggestion: $include="call" But i find this just as clear: ;#INCLUDE DateFunc, next line loads all Functions in DateFunc.kix for global use Call "%KixInclude%DateFunc.kix" ps. The script: DateFunc.kix, can not be used on dates before year 1 The script: DateFunc.kix, has a year 10,000 problem Erik [This message has been edited by kholm (edited 08 May 2001).] New version of Function: DayName Errors in previous version
[This message has been edited by kholm (edited 08 May 2001).]
|
cj
|
(MM club member)
|
2001-05-08 02:12 AM
|
|
|
|
|
Re: #Include ?
|
|
I have just opted for the CALL as the include now:at the top of every script is break on cls ; includes call "thisfunction.UDF" call "thatfunction.UDF" the rest of the script. cj
|
kholm
|
(Korg Regular)
|
2001-05-08 04:06 AM
|
|
|
|
|
Re: #Include ?
|
|
In my previous post on this topic:Search for: UdfLoaded in my previous post for comments explaining the purpose of UdfLoaded UdfLoaded() is a New wish to Ruud. I have mailed this wish to Ruud Example of using UdfLoaded(): ;Function Required in another UDF-library ;#IfINCLUDE If Not UdfLoaded("Mod") ; Neaded function Call %KixInclude% + "MathFunc.kix" ; Neaded function includede in: MathFunc.kix EndIf Erik
[This message has been edited by kholm (edited 08 May 2001).]
|
JensKalski
|
(Starting to like KiXtart)
|
2001-05-31 09:47 PM
|
|
|
|
|
Re: #Include ?
|
|
I think that it is the easiest way (for me, not for Ruud ) programming with modules in KiX2001 to extend the CALL-Command with an optional parameter for calling functions in an external script.In this way I can build files with a lot of functions like a library.
------------------ Jens Kalski eMail: jens@kalski.de
|
cj
|
(MM club member)
|
2001-06-02 07:35 AM
|
|
|
|
|
Re: #Include ?
|
|
I am doing something like this now:Save all my UDFs as .UDF and told TextPad to treat them as KiX sctipts for formatting. This means I can keep them together and sepatate at the same time. Create a few KiX scripts that call various UDFs, eg. Maths.k2k is call Sin.udf call cos.udf call atan.udf call Polar2Rect.udf call Rect2Polar.udf and graphics.k2k is call DrawLine.udf call cjBox.udf call cat.udf (color+at) so, if I need maths functions, I just Call maths.k2k and if I need graphics, I just Call graphics.k2k cj ------------------ cj's scripts page cj's User Guide - 14 May 2001 chrismat@ozemail.com.au
|
|
Re: #Include ?
|
|
I agree - an INCLUDE statement would clarify things.
|
Lonkero
|
(KiX Master Guru)
|
2001-07-08 04:22 PM
|
|
|
|
|
Re: #Include ?
|
|
Soon we will have full functioning header-files...cool. still need to have some text in version 2k1 help! and places to find the udf's/libraqries... maybe scriptlogig's page. I think kixtart.org should have some site for collecting the udf's, 'cause scriptlogic does not funcy me at all. and it should give nicer look from outside if everything is under .org domain
|
Bryce
|
(KiX Supporter)
|
2001-07-08 04:46 PM
|
|
|
|
|
Re: #Include ?
|
|
I was planning on getting the "kixscripts.org" domain name registered, and host it on my server (http://kixscripts.isorg.net). I was wanting to turn it into a user community ran script repository. would this be a good idea or not? Bryce
|
MCA
|
(KiX Supporter)
|
2001-07-15 06:37 AM
|
|
|
|
|
Re: #Include ?
|
|
Dear,Good idea. #include <filename> isn't for us the same as a call statement. #include <filename> means for us: at this point it looks like your code was situated at that point. it make it possible to reuse same code in different scripts without copy the code in it. and it make it also easily to maintain such code. the code can be any group of statements. it isn't necessary that it is a standalone working script at all.
Greetings.
|
cj
|
(MM club member)
|
2001-07-17 02:52 AM
|
|
|
|
|
Re: #Include ?
|
|
Bryce, go for it.cj
|
Lonkero
|
(KiX Master Guru)
|
2001-07-17 01:06 PM
|
|
|
|
|
Re: #Include ?
|
|
MCA, well I don't think udf's as standalone working scripts and still call can be used for them. if #include will be added (as I hope) I might suggest then also disabling this feature from call. like, it can be used only to call scripts that work on themselfs too. (?) include might then also, like kix does for .kix/.scr-files, as default search for .udf-extension. and maybe even only accept files that ar of that type.btw, .scr is not so good extension at all. when you think that you have also screensavers sharing that extension. never used it, never needed it, never vote for it. and Bryce, it really is good idea. I rather keep my udf's out from scriptlogig's site. the fact that they are making money with kix does make me trust them as much as none.
|
MCA
|
(KiX Supporter)
|
2001-07-18 03:54 AM
|
|
|
|
|
Re: #Include ?
|
|
Dear,Of course UDF isn't a standalone running script, but it is a complete part of code. For us is an UDF the same as any kind of group of statements. Greetings.
|