Sub Function

Purpose

Subtracts two numeric (integer) expressions.

Syntax

Sub x, y( command)
% = i Sub j)( operator)
% = Sub(i, j [,m, …)( function)

x:any numeric variable
y:any numeric expression
i, j:integer expression

Description

Sub x, y subtracts the expression y from value in variable x.

The operator i Sub j and function Sub(i, j, …) return the difference between integer expressions. In case one of the parameters isn't an integer, it is converted to a 32-bit value first (using CInt).

Example

Debug.Show

Dim b# = 1.5

Trace b# Sub 3          // CInt(b#) - 3 = -1

Trace Sub(b#, 3)        // CInt(b#) - 3 = -1

Sub b#, 3 : Trace b#    // b# = -1.5

b# = 2.5

Trace b# Sub 3          // CInt(b#) - 3 = -1

Trace Sub(b#, 3)        // CInt(b#) * 3 = -1

Sub b#, 3 : Trace b#    // b# = -0.5

Remarks

Although the command Sub can be used with any numeric variable, the usage of integer variables is recommended in order to achieve the maximum optimization for speed.

Instead of Sub x, y, you can use:

x = x - y

x := x - y

x -= y

When integer variables are used Sub doesn't test for overflow!

The Add(), Sub(), Mul() and Div() functions can be mixed freely with each other. For example

l% = Sub(5 ^ 3, 4 * 20 + 3)

// ...or...

l% = Sub(5 ^ 3, Add(Mul(4, 20), 3))

See Also

+, -, *, /, \, Add, Mul, Div, ++, --, +=, -=, /= , *=, Operator Hierarchy

{Created by Sjouke Hamstra; Last updated: 24/06/2017 by James Gaite}