Quote:

Any ideas?




Yes, you need to cast the adjustment day value to an integer (it will be a string).

Here is a complete solution.

Note the following enhancements:
  • Imported variable names are prefixed with an underscore to avoid clashes with your own variables - this is documented in the script and you can change it if you wish.
  • Illegal characters in variable names are replaced with underscores.
  • The variable parse routine will handle values with embedded quotes (' and " characters)
  • Works with SetOption("Explicit","ON") - variables are declared with global scope.


Give it a go and let us know how you get on.

Code:
Break ON


$=SetOption("Explicit","ON")

Dim $sVarsPath,$fdVars
Dim $sLine,$s
Dim $sVarName,$sVarValue
Dim $sAllowed,$iIndex

$sAllowed="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"

$fdVars=FreeFileHandle()
If Not $fdVars funFatal("Cannot get free file handle") EndIf

$sVarsPath="c:\temp\envvars.bat"
If Open($fdVars,$sVarsPath) funFatal("Cannot open file '"+$sVarsPath+"' for reading.") EndIf

; Load environment variables.
$sLine=ReadLine($fdVars)
While @ERROR=0
If Left($sLine,4)="SET "
$iIndex=InStr($sLine,"=")
If Not $iIndex $iIndex=Len($sLine)+1 EndIf
$s=SubStr($sLine,5,$iIndex-5)
$sVarName="_" ; Start variable name with "_" to avoid namespace clashes
; Remove any illegal characters from variable name
While $s <> ""
If InStr($sAllowed,Left($s,1))
$sVarName=CStr($sVarName)+Left($s,1)
Else
$sVarName=CStr($sVarName)+"_"
EndIf
$s=SubStr($s,2)
Loop
; Create global variable
$=Execute("Global $$"+$sVarName)
$sVarValue=SubStr($sLine,$iIndex+1)
; Remove any tricky quote marks from value and assign to KiXtart variable
$=Execute("$$"+$sVarName+"='"+Join(Split($sVarValue,"'"),"'+Chr("+Asc("'")+")+'")+"'")
EndIf
$sLine=ReadLine($fdVars)
Loop

$=Close($fdVars)

"Begin prompting at "+DateCalc(@DATE,Cint($_days_to_retain_full_workstation_backup)) ?

Function funFatal($s)
CStr($s)+@CRLF
If @ERROR "Reason: ["+@ERROR+"] "+@SERROR+@CRLF EndIf
Quit @ERROR
EndFunction

;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