LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel_RangeSort

I'm trying to sort a list of name but I always got an error.

The code is the follows:

void SortAnagrafica (void)
{
 int     i = 0, j = 1;
 HRESULT    esito = 0;
 ExcelObj_App  ExcelAppHandle = 0;
 VARIANT    TempVariant;

 
 // Open new Range for Worksheet
    esito = CA_VariantSetCString (&MyCellRangeV, "A1:A1000");
    // Get Sheet
    esito = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(SheetNr), &ExcelWorksheetHandle);
    esito = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);
 CA_VariantClear(&MyCellRangeV);
    // Make range Active   
//    esito = Excel_RangeActivate (ExcelRangeHandle, &ErrorInfo, NULL);
 
 while (OratorioEstivo[i].Progressivo != 0)
 {
  CA_VariantSetCString (&MyVariant, Anagrafica[i].Cognome);

  Excel_RangeSetItem (ExcelRangeHandle, &ErrorInfo, CA_VariantInt(i+1), CA_DEFAULT_VAL, MyVariant);
 
  i++;
 }

 esito = CA_VariantSetCString (&MyCellRangeV, "A1:A1");
 esito = CA_VariantSetBool (&TempVariant, FALSE);
 esito = Excel_RangeSort (ExcelRangeHandle, &ErrorInfo, MyCellRangeV, ExcelConst_xlAscending, CA_VariantNULL(), CA_VariantNULL(), ExcelConst_xlAscending, CA_VariantNULL(), ExcelConst_xlAscending,
                          ExcelConst_xlNo, CA_VariantNULL(), TempVariant, ExcelConst_xlSortRows, ExcelConst_xlPinYin, &MyVariant); 
}

 

The return value is: -2147352567

Do you have some suggests for me?

 

Fabrizio

0 Kudos
Message 1 of 3
(2,504 Views)

Hi FabriF,

 

it's pretty difficult to dive in a code like this a find out where the problem is without even seeing how the Excel sheet is organized. I suggest you do some debugging and print intermediate values, maybe trying on a smaller Excel sheet just so that you can print out arrays and see where the problem is.

 

Best,

 

CorraDIT

0 Kudos
Message 2 of 3
(2,434 Views)

Thanks a lot.

I'll try

0 Kudos
Message 3 of 3
(2,427 Views)