Vanguard Software
Forecasting & Planning Solutions

contents.gifindex.gifprev1.gifnext1.gif

Step-by-Step Instructions

Open DecisionScript to the default screen, or point to New in the File menu and click Blank Script dsc00064.gif. To create a script that computes a monthly mortgage payment, type the following formula in the Definition Window:

Root:={
Get Data;
Say Result;
}

When you have finished entering the formula, click anywhere in the Tree Window to accept the definition.

The definition for Root is a simple procedure that tells DecisionScript to perform two steps: execute the formula for Get Data, and then execute Say Result.

Note that node names can contain spaces in DecisionScript. This is different from standard JavaScript, which does not allow spaces in identifiers.

After entering the definition for Root, two branches, Get Data and Say Result, will be automatically added to the tree.

dsc00065.gif

To define Get Data, select the node in the Tree Window and type the following function in the Definition Window:

Get Data:=dialog

Dialog is a DecisionScript function that allows a user to input information using a fill-in-the-blank format. The actual text that prompts the user is typed in the Form Window. For the loan payment example, the text should appear as follows:

Enter your loan information below:

Principal: ^(Real)^^^^^^^^^^^^^
Interest rate: ^(Real)="7%";^^^^^^^
Term: ^MENU=[3,[10,20,30]];

The codes beginning with a ^ character define input fields. You can simply type these codes yourself, but is it often easier to build them using options in the toolbar.

dsc00066.gifdsc00067.gifdsc00068.gif  dsc00069.gifdsc00070.gifdsc00071.gifdsc00072.gifdsc00073.gifdsc00074.gifdsc00075.gifdsc00076.gif

To create an input field, just place the cursor where you want the field to begin. Then, click on the appropriate toolbar button. For example, to create the form for Get Data, begin by entering just the text items:

Enter your loan information below:

Principal:
Interest rate:
Term:

Next, position the cursor after "Principal: " and click the One-Line Text Box button dsc00077.gif. This will bring up a dialog box where you specify details about the field you want to create. Be sure to choose Floating point number and Required in the Type field.

dsc00078.gif

When you click OK, DecisionScript inserts the appropriate field codes.

Enter your loan information below:

Principal: ^(Real)^^^^^^^^^^^^^
Interest rate:
Term:

Repeat this process for the remaining fields. However, use the Drop-Down Menu tool dsc00079.gif for the Term field. Once you finish defining the input fields, click the Tree Window to accept the additions.

More information about the codes used to create input fields can be found in the online help system's description of the dialog function.

dsc00080.gif

To see how this input screen will look when you run your script, place your cursor in the Tree Window and click the Run Local toolbar button dsc00081.gif.

dsc00082.gif

One problem with this form is that the input fields are not vertically aligned. You can line up items in columns using tables. To do this, position the cursor before the first input field and press the Tab key. This will create a table that contains the following:

Principal:
^(Real)^^^^^^^^^^^^^

To cause the contents of the next row to join the table, position the cursor at the end of the table and press Delete, then press Enter. To divide the contents of the second row into two cells, position the cursor before the second input field and press the Tab key. Finally, repeat this procedure for the Term line.

The result will look like this:

dsc00083.gif

Now, run your script again to see the difference.

dsc00084.gif

To see how your script will look when it is run via the Internet, click the Run in Browser toolbar button dsc00085.gif.

dsc00086.gif

Next, you need to define the node Say Result. To do this, select the node in the Tree Window and type the following in the Definition Window:

Say Result:=say

In the Form Window, type the text you want your Web site visitor to see:

Your monthly payment is: <%Payment%>.

Once you accept the text (by clicking somewhere in the Tree Window), Payment will appear as a child of Say Result.

dsc00087.gif

To define Payment, select the node in the Tree Window and type the following formula in the Definition Window:

Payment=pmt(
Get Data[0],
Get Data[1]/12,
selecteditem(Get Data[2])*12
)

Pmt is a DecisionScript function that calculates the monthly payment for an installment loan given the principal, interest rate, and term. You get these values by picking individual items out of the result list created by Get Data. Remember that the definition for Get Data caused a form to be displayed that has three input fields (principal, interest, and term). Since it has three input fields, the result is a list of three response values. You can pick individual items out of the result list using the List Element operator []. Get Data[0] is the first element in the list and Get Data[1] is the second element. Since the third element in Get Data is generated by a drop-down menu, you need to use the selecteditem function to extract the particular value that the user chose. Drop-down menus normally return the entire list of options as well as the selected option.

Since you want to calculate monthly, rather than annual, payments given annual interest rates and terms, you must divide the interest rate by 12 and multiply the term by 12. This scaling is done in the definition for Payment.

To format the result so that it appears as currency with two decimal places, highlight the Payment node in the Tree Window and click the Currency Style format tool dsc00088.gif.

When you run your script now, you should see a final window similar to the one below.

dsc00089.gif

  Forecasting Software  |  Strategic Planning Software  |  Decision Support Software
Decision Tree Analysis  |  Monte Carlo Simulation Software  |  Risk Analysis Software
Portfolio Analysis  |  Expert System Software  |  Online Surveys

Contact Us  |  Terms of Use  |  Privacy Policy  |  Site Map
Vanguard Software
© 2010 Vanguard Software Corporation
Home Products Solutions Services Customers Partners Company
Vanguard
Applying science to business management
Vanguard
Print this page   Email this page to a friend