LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

type mismatch error

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

0 Kudos
Message 1 of 4
(3,637 Views)
This Knowledge base is for VB, but anyway, does it help? http://digital.ni.com/public.nsf/allkb/8800DECF0D358C9D86256B1700656C04?OpenDocument
0 Kudos
Message 2 of 4
(3,609 Views)

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"); 
}

0 Kudos
Message 3 of 4
(3,598 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(3,593 Views)