Thursday, January 3, 2019


Maths functions in vbscript

Below is the list of all maths functions in vb script

  1. Abs 
  2. Atn 
  3. Cos 
  4. Exp 
  5. Fix 
  6. Int 
  7. Log 
  8. Rnd 
  9. Sgn 
  10. Sin 
  11. Sqr 
  12. Tan 
  13. round
Let us have a look at each of these functions with examples.

'To find the absolute value 
Msgbox Abs(-11) 'prints 11

'To round the number
Msgbox round(22.346,2)  'prints 22.35

'To find the square root of the number
Msgbox Sqr (4)  'prints 2


Msgbox Exp(2)  'e^2

Difference between int and fix is that - If the number is negative, int  will return smallest possible integer value while fix will return largest possible integer value 
For positive numbers, both int and fix work the same way.
Msgbox Int (-8.4)  ' returns -9
Msgbox Fix(-8.4) 'returns  -8

'Calculates natural logarithm to the base e
Msgbox Log(10)

'gets the random number 
Msgbox Rnd()

'We must use Randomize function before Rnd to get different values

'To get the random numbers between 2 integers
max=100
min=1
Randomize
Msgbox (Int((max-min+1)*Rnd+min))

'This functions returns the integer number -1,0 or 1 depending upon the sign of the number.
'If the sign of the number is negative, -1
'if the number is zero , 0
'If the sign of the number is positive, 1

Msgbox Sgn(-11)  'prints -1


'Used for geometric calculations
Msgbox Sin(90) 
Msgbox Tan(45)
Msgbox Atn(45) 
Msgbox Cos(0)



0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

Blog Archive