#79927 - 2001-04-17 01:31 PM
Re: #Include ?
|
Anonymous
Anonymous
Unregistered
|
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.
|
Top
|
|
|
|
#79928 - 2001-05-03 12:25 AM
Re: #Include ?
|
kholm
Korg Regular
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
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
|
Top
|
|
|
|
#79930 - 2001-05-08 12:50 AM
Re: #Include ?
|
kholm
Korg Regular
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
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).]
|
Top
|
|
|
|
#79933 - 2001-05-31 09:47 PM
Re: #Include ?
|
JensKalski
Starting to like KiXtart
Registered: 2000-12-13
Posts: 186
Loc: Germany
|
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
_________________________
Jens Kalski
|
Top
|
|
|
|
#79934 - 2001-06-02 07:35 AM
Re: #Include ?
|
cj
MM club member
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
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
|
Top
|
|
|
|
#79935 - 2001-06-06 07:14 PM
Re: #Include ?
|
Anonymous
Anonymous
Unregistered
|
I agree - an INCLUDE statement would clarify things.
|
Top
|
|
|
|
#79939 - 2001-07-17 02:52 AM
Re: #Include ?
|
cj
MM club member
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 425 anonymous users online.
|
|
|