From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ExcelRpt_ReadData crashing when it encounters excel cell error

I'm using CVI 2013 sp2 to read in values from an excel spreadsheet.

Usually the program runs just fine, but if there is a cell error (e.g. #REF!, or #DIV/0!) in the second row or later it crashes. Strangely, it works just fine if the first row has the cell error, it's just the second row that crashes it.

It looks like in the CVI built in function ExcelRpt_ReadData in excelreport.c detects the cell error and tries to use the error catching to exit the function. Once it triggers the error catching it tries to release the memory it had allocated and crashes because the memory has not actually been populated with the contents of the cells with #REF! errors. That memory release is on line 2086 of excelreport.c.

The error it throws is:

FATAL RUN-TIME ERROR: "c:\...\toolslib\activex\excel\excelreport.c", line 2086, col 13, thread id 0x000032BC: The program has caused a 'General Protection' fault at 0x7714E43E.

 

I've attached a project which demonstrates the problem. To run it, you'll have to change PATH on line 18 to the full path of the excel file included in the .zip. I included 3 Excel files, one ends with Good, because the program runs as desired with that one. With the next one, Medium, it runs fine despite the #REF error in the 1st row, which is what I want it to do. For the third one, Bad, it crashes since the #REF is on the 2nd row. You can easily choose which to run by changing which line is uncommented.

 

Guidance on how to get it to exit politely (like it does for Medium) for Bad instead of crashing would be greatly appreciated.

0 Kudos
Message 1 of 6
(3,442 Views)

Hi AaronAnd,

 

I tried to run your code, but the build is failing due to undefined symbols referenced in the Demo.obj file. Are you getting this error as soon as you read the cell or is it post-pulling the data?

Mathew H.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(3,414 Views)

I just tried opening what I had uploaded, and I got the same issue. To fix this you need to load the excelreport instrument which is found in C:\Program Files (x86)\National Instruments\CVI2015\toolslib\activex\excel\excelreport.fp by default. I guess I just loaded the instrument in that session instead of adding it to the project, sorry about that.

Thanks for looking into this issue!

0 Kudos
Message 3 of 6
(3,407 Views)

Do you know how many times you can read from the excel file without it breaking or is it the first time it hits the first #REF! after not reading one at the beginning?

 

It looks like somehow you end up pointing to memory that the ExcelRpt_ReadData is trying to free and that is calling the General Protection fault.

Mathew H.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 6
(3,378 Views)

If there are no cell errors in the excel file, it can read many lines (multiple hundred) and not crash. If it hits a cell error anywhere but the first line of data it crashes. The crash is certainly triggered by trying to free memory, I just can't figure out why it's different if it's on the first line or a later line.

0 Kudos
Message 5 of 6
(3,373 Views)
Have you been able to track down which iteration of reading from the excel file it fails after reading that first invalid cell? Does it read the first line of data fully then crash on the first data of the next line or the first time it reads an invalid cell after on the second line? Basically which cell will break it and what conditions have to be met to cause it to break?
Mathew H.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 6
(3,357 Views)