Internal Functions
In the previous chapters, you have seen some internal
functions: MsgBox(), InputBox(), LoadPicture(), etc.
In the rest of today's lesson, you'll learn about
some more internal functions.
The Numeric Functions
Int(number)
Fix(number)
The number can be any numeric literal, variable,
or expression, including another embedded function.
Both Int and Fix remove the fractional part of number
and return the resulting integer value. In the following
statements, the remark shows each function's return
value.
int1 = Int(5.2) '
5
int2 = Fix(5.2) '
5
int3 = Int(-5.8) ' -6
int4 = Fix(-5.8) ' -5
The difference between Int and Fix is that if number
is negative, Int returns the first negative integer
less than or equal to number, whereas Fix returns
the first negative integer greater than or equal to
number. For example, Int converts -5.8 to -6, and
Fix converts -5.8 to -5.
Abs(number)
The Abs() function returns
a value of the same type that is passed to it specifying
the absolute value of a number. The absolute value
of a number is its unsigned magnitude. For example,
ABS(-5) and ABS(5) both return 5.
The Sqr() function returns
the square root of any positive number. In the following
statements, the remark shows the return value.
int1 = Sqr(4) '
2
int2 = Sqr(36) ' 6
Visual Basic supports several advanced scientific
and trigonometric functions, but we will not discuss
about them.
|