Gang:

Ok – here’s my un-orthodox approach to handling dates and floating-point math
in KiX

The following script instantiates an instance of Excel, prompts for a formula, plugs it into Excel, then displays the calculated value.

Note: the KiX OleReleaseObject() function doesn't seem to want to release out-of-proc servers (excel.exe). I think word.exe has the same problem. Not sure if this is a KiX OLE thing or an Office OLE thing but can anybody fix ?

Here's some relevant things to try:

Formula: 1+1

Formula: .001 + .00234 (for you math hounds)

Formula: text(datevalue("20-JUN-2000")-14,"dd-mmm-yyyy") (jochen hmmm ?)

Formula: datevalue("20-JUN-2000")-datevalue("03-JUL-1969") (days between)

If anyone has trouble cutting and pasting, please advise.

Anyway - here goes:

code:

break on cls


;------------------------------------------------
; OLE Formula 1 Driver (hehe)
;
; Enter "quit" to quit
;------------------------------------------------


; Create an instance of Excel (excel.exe)


$excel = olecreateobject ( "excel.application" )


if $excel = 0


?"Excel (ole) is not supported on this machine"


exit


endif


; Comment/Uncomment next line for the visuals
; Remember to re-focus back to your DOSBOX if you do


; $rs = oleputproperty ( $excel, "visible", "b", "1" )


; Disable alerts (i.e. don't ask if I want to save my work)


$rs = oleputproperty ( $excel, "displayalerts", "b", "0" )


; Get a handle to the workbooks object


$workbooks = val("&"+olegetproperty ( $excel, "workbooks" ))


; Open a new workbook & sheet


$rs = olecallfunc ( $workbooks, "add" )


; Get a handle to the default active cell (A1)


$cell = val("&"+olegetproperty ( $excel, "activecell" ))


while 1


?
?"Formula : " gets $formula


if $formula = "quit" goto finish endif


$rs = oleputproperty ( $cell, "formula", "s", "=$formula" )


?"Answer : " olegetproperty ( $cell, "value" )


loop


:finish


$rs = olecallfunc ( $excel, "exit" )


$rs = olereleaseobject ( $excel )


?
?"Use taskmgr.exe to manually terminate excel.exe"
?


exit


Shawn.

[This message has been edited by Shawn (edited 20 June 2000).]