Abs Function


Abs Function

Class

System.Math

Syntax

     Dim result As type = Math.Abs(value) 


type (required; signed numeric type)

One of the following data types: Decimal, Double, Integer, Long, SByte, Single, or Short


value (required; expression of type type)

A number with the absolute value that is to be returned

Description

The Abs function returns the absolute value of value. The source and return data type are always the same.

Usage at a Glance

  • This is a shared member of the System.Math class, so it can be used without an instance.

  • If Option Strict is Off, you will be able to pass string representations of numbers to the Abs function. Use the IsNumeric function to confirm that the string contains a valid number.

Example

This sample returns the difference between two integers, regardless of their order.

     Public Function IntegerDiff(ByVal first As Integer, _           ByVal second As Integer) As Integer        Return Math.Abs(second - first)     End Function 

Version Differences

In VB 6, Abs is an intrinsic VB function. In the .NET platform, it is a member of the System.Math class and not directly part of the VB language.

See Also

Sign Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net