Numbers


VBA.Abs

ABS - Returns the absolute value of a number.

'VBA Code
Abs(-40)

'C# Equivalent
System.Math.Abs(-40)

VBA.CInt

CINT - Returns a number converted to an integer data type.

'VBA Code
CInt(0.2)

'C# Equivalent
System.Convert.ToInt32(0.2)

VBA.Exp

EXP - Returns the base of natural logarithm raised to a power

'VBA Code


'C# Equivalent


VBA.Hex

HEX - Returns the number converted to a hexadecimal

'VBA Code
Hex(iValue)

'C# Equivalent
iValue.ToString("X")

VBA.Fix

FIX - Returns the integer portion of a number.

'VBA Code


'C# Equivalent


VBA.Int

INT - Returns the number rounded down to the nearest integer.

'VBA Code
Int(0.9) = 0

'C# Equivalent
System.Math.Floor(0.9)

VBA.IsNumeric

ISNUMERIC - Returns the value indicating if an expression contains a number.

'VBA Code
IsNumeric(sCharacter)

C# Equivalent, single character
System.Char.IsNumber(sCharacter.Chars(0)) = True;

C# Equivalent, entire string
int integerValue;
string stringValue = "2030";
bool result = int.TryParse(stringValue, out integerValue);
if (result == true)
{ // this string contains a valid integer
}

VBA.Log

LOG - Returns the natural logarithm of a number

'VBA Code


'C# Equivalent


VBA.Mod

MOD - Returns the remainder after division

'VBA Code


'C# Equivalent


VBA.Round

ROUND - Returns a number rounded to a given number of decimal places.

'VBA Code
Round(0.149,2)

'C# Equivalent
System.Math.Round(0.149,2, MidPointRounding.AwayFromZero)

VBA.Rnd

RND - Returns a random number between 0 and 1

'VBA Code


'C# Equivalent


VBA.Sgn

SGN - Returns the sign of a number.

'VBA Code
Sgn(1)

'C# Equivalent
System.Math.Sign(1)

VBA.Sqr

SQR - Returns the square root of a number.

'VBA Code
Sqr(9)

'C# Equivalent
System.Math.Sqrt(9)

Integer Division

C# truncates, VB.Net rounds

Dim itotal As Integer = 20; 
Dim ivalue As Integer = 3
Dim iresult As Integer = itotal / ivalue

int itotal = 20; 
int ivalue = 3
int iresult = itotal / ivalue;

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext