Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29249 Discussions

Problem, with accessing Excel through COM

cobek
Beginner
505 Views
I wanted to change original function i have got from Fortran Module Wizard for Excel02.
The variables RowIndex and ColumnIndex are originally supposed to be VARIANTS. I thought
to make them integers, and inside of the body of the function to apply neccessary
transformation to variants. The return value should be pointer
to range object (specified by RowIndex and ColIndex).
Does any have an idea why this does not work?


FUNCTION Worksheet_Cells($OBJECT,RowIndex,ColumnIndex,$STATUS)

use....!whatever is neccessary

!DEC$ ATTRIBUTES DLLEXPORT :: Worksheet_Cells
implicit none
integer(INT_PTR_KIND()),intent(IN) :: $OBJECT !Object Pointer
!DEC$ ATTRIBUTES VALUE :: $OBJECT
integer :: RowIndex
!DEC$ ATTRIBUTES REFERENCE :: RowIndex
integer :: ColumnIndex
!DEC$ ATTRIBUTES REFERENCE :: ColumnIndex
integer(4),intent(OUT),optional :: $STATUS ! Method status
!DEC$ ATTRIBUTES REFERENCE :: $STATUS
integer(4) $$STATUS,ret
integer(INT_PTR_KIND()) invokeargs
integer(INT_PTR_KIND()),volatile :: $RETURN
integer(INT_PTR_KIND()) Worksheet_Cells
type(VARIANT) vRowIndex,vColumnIndex

!transformation of the integers in variants..might be wrong
call VariantInit(vRowIndex)
vRowIndex%VT=VT_I2
vRowIndex%VU%LONG_VAL=RowIndex
call VariantInit(vColumnIndex)
vColumnIndex%VT=VT_I2
vColumnIndex%VU%LONG_VAL=ColumnIndex

invokeargs=AUTOALLOCATEINVOKEARGS()
call AUTOADDARG(invokeargs,'$RETURN',$RETURN,AUTO_ARG_OUT)
call AUTOADDARG(invokeargs,'$ARG1',vRowIndex,AUTO_ARG_IN)
call AUTOADDARG(invokeargs,'$ARG2',vColumnIndex,AUTO_ARG_IN)
$$STATUS=AUTOINVOKE($OBJECT,238,invokeargs)
if(present($STATUS)) $STATUS=$$STATUS
Worksheet_Cells=$RETURN
call AUTODEALLOCATEINVOKEARGS(invokeargs)
ret=VariantClear(vRowIndex)
ret=VariantClear(vColumnIndex)
END FUNCTION Worksheet_Cells

thnaks
0 Kudos
1 Reply
cobek
Beginner
505 Views
Ok..now it works, sorry for disturbing...for those who might be interested this is how it should look like:

FUNCTION Worksheet_Cells($OBJECT,RowIndex,ColumnIndex,$STATUS)
!DEC$ ATTRIBUTES DLLEXPORT :: Worksheet_Cells
implicit none
integer(INT_PTR_KIND()),intent(IN) :: $OBJECT !Object Pointer
!DEC$ ATTRIBUTES VALUE :: $OBJECT
integer :: RowIndex
!DEC$ ATTRIBUTES REFERENCE :: RowIndex
integer :: ColumnIndex
!DEC$ ATTRIBUTES VALUE :: ColumnIndex
integer(4),intent(OUT),optional :: $STATUS ! Method status
!DEC$ ATTRIBUTES REFERENCE :: $STATUS
integer(4) $$STATUS,ret
integer(INT_PTR_KIND()) invokeargs
integer(INT_PTR_KIND()),volatile :: $RETURN
integer(INT_PTR_KIND()) Worksheet_Cells
type(VARIANT) vRowIndex,vColumnIndex

call VariantInit(vRowIndex)
vRowIndex%VT=VT_I2
vRowIndex%VU%SHORT_VAL=RowIndex
call VariantInit(vColumnIndex)
vColumnIndex%VT=VT_I2
vColumnIndex%VU%SHORT_VAL=ColumnIndex
invokeargs=AUTOALLOCATEINVOKEARGS()
call AUTOADDARG(invokeargs,'Cells',$RETURN,AUTO_ARG_OUT,VT_DISPATCH)
call AUTOADDARG(invokeargs,'$ARG1',vRowIndex,AUTO_ARG_IN)
call AUTOADDARG(invokeargs,'$ARG2',vColumnIndex,AUTO_ARG_IN)
!$$STATUS=AUTOINVOKE($OBJECT,238,invokeargs)
$$STATUS=AUTOGETPROPERTYBYID($OBJECT,238,invokeargs)
if(present($STATUS)) $STATUS=$$STATUS
Worksheet_Cells=$RETURN
call AUTODEALLOCATEINVOKEARGS(invokeargs)
ret=VariantClear(vRowIndex)
ret=VariantClear(vColumnIndex)
END FUNCTION Worksheet_Cells
0 Kudos
Reply