03-02-2010 11:48 PM
Hi,
when i was trying to call the function CA_VariantGetChar(&MyVariant,&ch);i am getting run time error as type mismatch (return value == -2147352571 [0x80020005]). pls help me out in solving this error so that i can copy text available in MyVariant copies into ch.
Variable declared: VARIANT MyVariant; char ch;
Regards,
raj
03-04-2010 12:29 AM
03-04-2010 02:43 AM
Hi,
i am working with labwindow/CVI.I am trying to read the content in the a cell of an excel sheet. i am getting the above error when i am trying with the below code. pls help me in solving this
for (i=0;i<ROWS;i++)
{
for (j=0;j<COLUMNS;j++)
{
// Ask for the ith by jth value of the range which returns a dispatch to a new single cell range
error = Excel_RangeGetItem (ExcelRangeHandle, &ErrorInfo, CA_VariantInt (i+1), CA_VariantInt (j+1), &MyVariant);
if (error<0) goto Error;
// Get the DISPATCH pointer
error = CA_VariantGetDispatch (&MyVariant, &MyDispatch);
if (error<0) goto Error;
// Create a new Range Object from DISPATCH pointer
error = CA_CreateObjHandleFromIDispatch (MyDispatch, 0, &ExcelSingleCellRangeHandle);
if (error<0) goto Error;
// Get the value of the Single Cell Range
error = Excel_GetProperty (ExcelSingleCellRangeHandle, &ErrorInfo, Excel_RangeValue2, CAVT_VARIANT, &MyVariant);
if (error<0) goto Error;
error = CA_VariantGetChar(&MyVariant,&ch);
if (error<0) goto Error;
// Free Variant element
CA_VariantClear(&MyVariant);
//Free Range Handle
ClearObjHandle (&ExcelSingleCellRangeHandle);
printf("%c ", &ch);
}
printf("\n");
}
03-04-2010 03:08 AM
A couple of ideas are coming to my mind in this discussion.
First of all, you do not tell us how ch is defined: this is a relevant information as the error is a 'type mismatch'; its absence prevents us to understand what is happening
Additionally, CA_VariantGetChar expects to read a single char value out of the variant, i.e. a single character. It seems difficult to me that an excel cell returns a char instead of a string: if I were you I will try to understand which data type is stored into the variant with CA_VariantGetType or at least CA_VariantHasChar and operate consequently using the proper function and data type. I personally would expect that the variant stores a string instead of a char.