Sunday, 23 February 2014

Math Functions


Abs([expr]))
Returns the absolute value of a specified expression.
Example:
' declare as double so the variable can store a decimal portion of a number.
Dim myNumb as Double
myNumb = Abs(3.14159)
' myNumb = 3
myNumb = Abs(-42)
' myNumb = 42


Int([expr]))
Fix([expr]))
Returns the integer part of a specified expression. the Fix() function does exactly the same as Int()
 

Example:
' declare as double so the variable can store a decimal portion of a number.
Dim myNumb as Double
myNumb = 3.14159
myNumb = Int(myNumb)
' myNumb now = 3


Randomize()
Rnd([number])
Generate a random number. The number is always less than 1 but greater than 0.
The [number] field is optional. the [number] field is to seed the random number generator. use Randomize() to generate a random seed. setting the [number] field will generate the same set of random numbers each time Rnd() is called.
 

Example: (this could be made to a function of it's own)
' declare variables.
Dim min as Integer
Dim max as Integer
Dim rNumb as Integer
' set our variables
min = 1
max = 100
' generate random seed.
Randomize
' generate a random number.
rNumb = Int((max - min + 1) * Rnd() + min)
' rNumb now contains a random number between 1 and 100.


Sqr([number]))
Returns the square root of number.
 

Example:
' declare the variable.
Dim myNumb as Double
myNumb = Sqr(9)
' myNumb = 3
myNumb = Sqr(47)
' myNumb = 6.85565460040104


Cos([angle]))
Sin([angle]))
Tan([angle]))
Atn([angle]))
Geomotry functions to calculate Cosine, Sine, Tangent, and Arctangent.

No comments:

Post a Comment