I am using a 3rd party hydraulic modeling program that provides its computational engine in a DLL and associated VBA module that provides the desired functions from the DLL to VBA.
I have a macro that I wrote that iterates on rows of a spreadsheet. Each row contains some inputs. At each row, the macro will load the model engine using the provided VBA commands, make some adjustments to the inputs, run the model engine using the VBA commands, and then write the outputs to Excel on the given row.
This works perfectly for a limited number of times. But inevitably a point is reached where the macro can no longer successfully load the model engine. I get no error messages, but all calls to the engine return zero values.
This happens two different ways. The first is in the middle of an attempt to run many iterations, but it also happens if I run small chunks. For example, it may happen in the middle of a run on 200 rows, but it will also happen eventually even if I run the macro on 10 rows at a time. In other words, the small 10 row runs will be successful for awhile, and I will save the workbook between each run. But eventually it will still reach a point where a small 10 row run will start generating all zero outputs. The only way I have found to fix this is to close the workbook and open it again; then I can start from where I left off and continue until the next point that I start getting zeros. (Upon reopening, I can successfully complete the row that I got stuck on the last time, so it's not a matter of bad inputs or bad code, in that sense.) But the rows are many and the workbook is large (takes long to open), so this is not feasible.
Could this be some kind of memory leak? I'm baffled, as it persists even across multiple macro runs. I would have thought that once one macro run completed successfully, all memory and everything would be cleared, and running the macro again on the next set of rows would be a fresh start. Apparently not... Something keeps piling up and closing the workbook is the only way to refresh it (that I know of at this point).
I have scoured the web for a solution and have found none. It's possible I don't know the right terms, since I'm not very familiar with DLLs in VBA.
Best guesses are very welcome; I'll try anything at this point.
I have a macro that I wrote that iterates on rows of a spreadsheet. Each row contains some inputs. At each row, the macro will load the model engine using the provided VBA commands, make some adjustments to the inputs, run the model engine using the VBA commands, and then write the outputs to Excel on the given row.
This works perfectly for a limited number of times. But inevitably a point is reached where the macro can no longer successfully load the model engine. I get no error messages, but all calls to the engine return zero values.
This happens two different ways. The first is in the middle of an attempt to run many iterations, but it also happens if I run small chunks. For example, it may happen in the middle of a run on 200 rows, but it will also happen eventually even if I run the macro on 10 rows at a time. In other words, the small 10 row runs will be successful for awhile, and I will save the workbook between each run. But eventually it will still reach a point where a small 10 row run will start generating all zero outputs. The only way I have found to fix this is to close the workbook and open it again; then I can start from where I left off and continue until the next point that I start getting zeros. (Upon reopening, I can successfully complete the row that I got stuck on the last time, so it's not a matter of bad inputs or bad code, in that sense.) But the rows are many and the workbook is large (takes long to open), so this is not feasible.
Could this be some kind of memory leak? I'm baffled, as it persists even across multiple macro runs. I would have thought that once one macro run completed successfully, all memory and everything would be cleared, and running the macro again on the next set of rows would be a fresh start. Apparently not... Something keeps piling up and closing the workbook is the only way to refresh it (that I know of at this point).
I have scoured the web for a solution and have found none. It's possible I don't know the right terms, since I'm not very familiar with DLLs in VBA.
Best guesses are very welcome; I'll try anything at this point.