Solve in Loop

I often get the question how to solve several instances in one go. In this article I provide a simple example.

The structure of execution is typically something ilke:

  1. Determine the collection of inputs
  2. For each input:
    1. Work that input

Let’s discuss these steps in detail:

Determine the collection of inputs

When you have multiple input files, you’ll probably want to determine the folder name. For this you can use the predeclared funtion DirectorySelect. Example code is:

ret := DirectorySelect(
    directoryname :  sp_BatchExcelInputFolder,
    directory     :  ".",
    title         :  "Please select folder to read the .xlsx input files from.");

Obtaining the collection of input files

With the directory name, the collection of input files can be obtained using DirectoryGetFiles.

    directory :  sp_BatchExcelInputFolder,
    filter    :  "*.xlsx",
    filenames :  sp_InputFileNames,
    recursive :  1);

Processing each of the input files

for i_fn do
    sp_Workbook := sp_BatchExcelInputFolder + sp_InputFileNames(i_fn);
    pr_ExecuteSingleRun( sp_Workbook );
endfor ;

Example used:

Excel inputs download

AIMMS project download

Was this helpful ?

Send us your Feedback !

Last Updated: February, 2019