Okay, now I'm in waay over my head.

One of the several things I'm trying to do with this code, is to grab a value from a text file, set it as a Kix variable, then mod @date against the variable using Jochen's DateCalc UDF.

Net/net is that I'm trying to obtain a calendar date X days in the future, where "X" is the numerical value taken from the 'set days_to_retain_full_workstation_backup=x' line in the text file, as $days_to_retain_full_workstation_backup in the KIX script.
Code:
;DateCalc=======================================================================================

Function DateCalc($date1, $DateOrMod, optional $SingleDigit)

Dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1
Dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2

$date1 = Split($date1,'/')
If Ubound($date1) <> 2
Exit 1
EndIf

$_intYear1 = Val($date1[0])
$_intMonth1 = Val($date1[1])
$_intDay1 = Val($date1[2])
If $_intMonth1 < 3
$_intMonth1 = $_intMonth1 + 12
$_intYear1 = $_intYear1 - 1
EndIf

$_intDate1 = $_intDay1 + ( 153 * $_intMonth1 - 457 ) / 5 + 365 * $_intYear1 +
$_intYear1 / 4 - $_intYear1 / 100 + $_intYear1 / 400 - 306

Select

Case VarType($DateOrMod) = 3

$_intDate2 = $_intDate1 + $DateOrMod
If InStr($_intDate2,'-') $_intDate2 = Val(SubStr($_intDate2,2,Len($_intDate2)-1)) EndIf

$_intYear2 = ( 100 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
) + (100*($_intDate2+306)-25)
) / 36525
$_intMonth2 = ( 5 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) + 456
) / 153
$_intDay2 = ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) - ( 153 * $_intMonth2 - 457
) / 5

If $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 EndIf


If NOT $SingleDigit
If Len($_intYear2 ) < 4
$_ = Execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next")
EndIf
$_intMonth2 = Right("0" + $_intMonth2,2)
$_intDay2 = Right("0" + $_intDay2,2)
EndIf

$DateCalc = '$_intYear2/$_intMonth2/$_intDay2'

Case VarType($DateOrMod) = 8

$DateOrMod = Split($DateOrMod,'/')
If Ubound($DateOrMod) <> 2
Exit 1
EndIf

$_intYear2 = Val($DateOrMod[0])
$_intMonth2 = Val($DateOrMod[1])
$_intDay2 = Val($DateOrMod[2])

If $_intMonth2 < 3
$_intMonth2 = $_intMonth2 + 12
$_intYear2 = $_intYear2 - 1
EndIf

$_intDate2 = $_intDay2 + ( 153 * $_intMonth2 - 457 ) / 5 + 365 * $_intYear2 +
$_intYear2 / 4 - $_intYear2 / 100 + $_intYear2 / 400 - 306

$DateCalc = $_intDate1 - $_intDate2
;comment the next line if you wish to return negative results also !!!
If InStr($DateCalc,'-') $DateCalc = Val(SubStr($DateCalc,2,Len($DateCalc)-1)) EndIf

Case 1

Exit 1

EndSelect

EndFunction
;===============================================================================================

Break on

Color c+/n

$dummy = SetOption('novarsinstrings','on')
;$dummy = SetOption('explicit','on') -- can't use explicit without dimming each $var_name
$dummy = SetOption('wrapateol','on')

If Open(1,'c:\temp\envars.bat') = 0

$raw_line = Trim(SubStr(Lcase(ReadLine(1)),5))

While @error = 0

$var_name = ''
$var_value = ''
$dummy = ''

;provide special handling for ldap path
If InStr($raw_line,'comppath')
For Each $element in Split($raw_line,'comppath' + Chr(61))
$var_name = 'comppath'
$var_value = $element
Next
GoTo set_var
EndIf

For Each $element in Split($raw_line,Chr(61))
Select
Case $var_name = '' $var_name = $element
Case $var_value = '' $var_value = $element
EndSelect
Next

If InStr($var_name,'-')
? $var_name Color r+/n ' $var_name contains operand - skipped' Color c+/n
GoTo next_line
EndIf

:set_var
? '$' + $var_name + '=' + $var_value
If $var_value = ''
Color r+/n "null - skipped" Color c+/n
GoTo next_line
EndIf

$dummy = Execute ("$" + $var_name + "='" + $var_value + "'")

:next_line
$raw_line = Trim(SubStr(Lcase(ReadLine(1)),5))

Loop

Close(1)

EndIf

;===============================================================================================

@CRLF + @CRLF

? '$days_to_retain_full_workstation_backup=' + $days_to_retain_full_workstation_backup

$begin_prompting_calc = DateCalc(@date, $days_to_retain_full_workstation_backup)

? '$begin_prompting_calc=' + $begin_prompting_calc

@CRLF + @CRLF

Get $

The problem is that $begin_prompting_calc is returning empty.

If I set NOVARSINSTRINGS to 'ON', $begin_prompting_calc appears as $_intYear2/$_intMonth2/$_intDay2 .

Any ideas?


Edited by xpanmanx (2004-09-14 11:11 PM)