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)


Related Posts:

  • Regular Expressions in vb script example Regular Expressions in vb script example Regular expressions BasicsDefinition :A regular expression is a pattern of characters(meta characters and special characters). General Applications of Regular Expression… Read More
  • Difference between procedures and functions in vb script Difference between procedures and functions in vb script Major difference between procedures and functions in vb script is that procedures can not return the value but functions can return the value.Procedure Example… Read More
  • Maths functions in vbscript Maths functions in vbscript Below is the list of all maths functions in vb script Abs  Atn  Cos  Exp  Fix  Int  Log  Rnd  Sgn  Sin  Sqr  Tan  round Let us … Read More
  • Classes in VBScript Classes in VBScript Here is an example that shows how we can create a class in QTP. Once we define the class, we can create its objects and then access its method and properties. 'declare the class book. Class Bo… Read More
  • String functions in vbscript String functions in vbscript Below is the list of string functions in vb script lcase ucase len left right mid ltrim rtrim trim replace strreverse string Instr Instrrev strcomp We are going to have a look at each St… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

151,819

Blog Archive