Abs (function)

<< Click to Display Table of Contents >>

Abs (function)

Abs(Num)

Returns the absolute value of the numeric value Num, i.e., removes its sign. If Num is zero, Abs returns zero.

The type of the return value corresponds to the type of the passed parameter Num. Exception: If Num is a Variant of VarType 8 (String) and can be converted to a number, the result will have the type Variant of VarType 5 (Double).

See also: Sgn

Example:

Sub Main

 Dim Msg, x, y

 x = InputBox("Enter a number:")

 y = Abs(x)

 Msg = "The absolute value of " & x & " is: " & y

 MsgBox Msg

End Sub