DPL 9 Help

Using Converted Spreadsheets in DPL Programs

Using Converted Spreadsheets in DPL Programs

A converted spreadsheet is a perfectly ordinary DPL program, consisting entirely of value, series, array, and string definitions, which can be edited any way you like. The most common modifications include adding decision and chance events, modifying the values to depend on the events, and adding a sequence section.

However, if you edit the converted spreadsheet file and then discover that you need to make changes in the spreadsheet and reconvert, you will lose all your edits. It is much easier to use the #include compiler directive, which allows you to convert and reconvert your spreadsheet without having to redo the other sections of your program.

To use #include, set up two program files: a main program file that contains the decision and chance definitions and the sequence section and a second file for the spreadsheet code. At the appropriate place in the main DPL program file, you can insert an instruction that tells the compiler to stop compiling this program file, go to the program file containing the spreadsheet code and compile it, and then come back and compile the rest of the main program file.

Main program file:

decision Marketing.{High,Average,Low} =
   10000,      // Marketing.High
   20000,      // Marketing.Average
   35000;      // Marketing.Low
chance Sales_Level.{High,Medium,Low} | Marketing =
   {.4,.5,.1},   // Marketing.High
   {.2,.5,.3},   // Marketing.Average
   {.1,.3,.6};   // Marketing.Low
value Sales_Level | Sales_Level =
   2500,      // Sales_Level.High
   3500,      // Sales_Level.Medium
   5000;      // Sales_Level.Low
#include c:\dpl\incl_ex.dpl

sequence:
decide to Marketing then
gamble on Sales_Level and get Net_Profit

Included converted spreadsheet file:

value Price = 15;
value Sales_Level = 3500;
value Gross_Profit = Price*Sales_Level;
value Marketing = 20000;
value Other_Costs = 5000;
value Net_Profit = Gross_Profit-Marketing-Other_Costs;

Using the #include directive is essentially the same as copying the entire contents of one file into another program and inserting the new file in a particular place. However, there is one subtle and useful difference. If you were to do this in the example, you would find that you would have two definitions for Marketing and two for Sales_Level. In each case, one definition would be a decision with values and the other a value from the spreadsheet.

//incorrect code
decision Marketing.{High,Average,Low} =
   10000,      // Marketing.High
   20000,      // Marketing.Average
   35000;      // Marketing.Low
chance Sales_Level.{High,Medium,Low} | Marketing =
   {.4,.5,.1},   // Marketing.High
   {.2,.5,.3},   // Marketing.Average
   {.1,.3,.6}    // Marketing.Low
value Sales_Level | Sales_Level =
   2500,      // Sales_Level.High
   3500,      // Sales_Level.Medium
   5000;      // Sales_Level.Low
value Price = 15;
value Sales_Level = 3500;
value Gross_Profit = Price * Sales_Level;
value Marketing = 20000;  // Already defined!
value Other_Costs = 5000;
value Net_Profit = Gross_Profit-Marketing-Other_Costs;
sequence:
decide to Marketing then
gamble on Sales_Level and get Net_Profit

Because you cannot have two value definitions with the same name, the compiler would give you an error message and the compilation would terminate. But, whenever included files contain variable definitions that duplicate definitions in the main program file, the definitions in the DPL Program are ignored. Functionally, the result is as follows. (Lines in italics are ignored.)

decision Marketing.{High,Average,Low} =
   10000,      // Marketing.High
   20000,      // Marketing.Average
   35000;      // Marketing.Low
chance Sales_Level.{High,Medium,Low} | Marketing =
   {.4,.5,.1},   // Marketing.High
   {.2,.5,.3},   // Marketing.Average
   {.1,.3,.6};   // Marketing.Low
value Sales_Level | Sales_Level =
   2500,      // Sales_Level.High
   3500,      // Sales_Level.Medium
   5000;      // Sales_Level.Low
value Price = 15;
value Sales_Level = 3500;
value Gross_Profit = Price * Sales_Level;
value Marketing = 20000;

value Other_Costs = 5000;
value Net_Profit = Gross_Profit-Marketing-Other_Costs;
sequence:
decide to Marketing then
gamble on Sales_Level and get Net_Profit

This allows you to avoid having to edit your converted spreadsheet to eliminate definitions that duplicate definitions in the main program.

Required Override

If you want to ensure that a variable in your program overrides a variable in the DPL Program you can add a required override to your definition. For example:

chance (*Sales_Level) Sales_Level.{High,Medium,Low} | Marketing = ...

If a node named Sales_Level is not found in the DPL Program DPL will issue an error message. The two names need not be the same, however when they are (as in this example), the definition can be shortened to

chance (*) Sales_Level.{High,Medium,Low} | Marketing = ...

Versions: DPL Professional, DPL Enterprise, DPL Portfolio

See Also

Converting Spreadsheets to DPL Programs