Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space WDESIGNER and version 24.0

In action script operations, the Designer supports the following basic arithmetic operations: multiplication, division, subtraction, and addition. Also, it is allowed to use parentheses like e.g. in 3*(4+2) instead of 3*4 + 3*2.

Info

The variables and literals involved in an arithmetic expression must all be of the same type. You cannot mix integers and floats.

Example Arithmetics

The following notations are valid arithmetics expressions:

Code Block
set resultInteger1 = integer1 + 3 * 4;
set resultInteger2 = integer2 + 5 / 3;
set resultInteger3 = integer3 - (3  - 4);
set resultInteger4 = integer4-6;

set resultFloat1 = float1 + 5.0 / 3.0;
set resultFloat2 = float1 + float2;
set resultFloat3 = float1 * float3;
set resultFloat4 = float1 / float4;

Some remarks:

  • If you provide the value 1 for integer2, the value of resultInteger2 will be 2.  The calculated result of 2.66 will be cut after the decimal point because the result value is of type integer.
    However, if you provide the value 1.0 for float1, the result will be 2.66.

  • The expression set resultFloat1 = 1 + 5 / 3 would cause a compilation error because 1, 5, and 3 are of type integer. If you want the result to be a float, you must specify the integers in float notation, thus appending '.0'.

DateTime Arithmetics

Besides doing arithmetic with plain numbers it is also possible to do DateTime arithmetic. It is allowed to add/subtract durations to/from a given DateTime object.

The following action script sample shows how to add one month to a given DateTime object:
Code Block
none
none
set resultDateTime = dateTime + convertDurationToDateTime("P1M");

Multiexcerpt include
SpaceWithExcerptINTERNAL
MultiExcerptNamecalculate_dates
PageWithExcerptINTERNAL:_designer_excerpts_asl
shouldDisplayInlineCommentsInIncludesfalse

In fact, these objects are represented as DateTime types but they are actually handled as durations. For the exact lexical definition of duration, refer to convertDurationToDateTime.

You can also use dedicated DateTime operations for these arithmetics (see DateTime Operations), e.g. add subtract using a duration structure as a parameter:

Code Block
none
none
create duration; 
set duration.months = 1; 

set resultDateTime = dateTime.add(duration);
set resultDateTime = dateTime.subtract(duration);
Note

It is not allowed to add up two dates.

Tip

To find out the duration between two dates better use the difference() operation instead of subtracting them.

Panel
titleOn this Page:
Table of Contents
OtpFloatingfalse

Multiexcerpt include
SpaceWithExcerptINTERNAL
MultiExcerptNameActionScript_Calculations_Example
PageWithExcerptINTERNAL:_designer_examples

rp
Panel
titleRelated Pages: