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:

  • Data Types in vbscript Data Types in vbscript In vb script all variables are initialized with the data type called variant. But we can have below sub-types in vb script. In below table we have mentioned all sub data types in vb sc… Read More
  • What are the different operators in vbscript? What are the different operators in vbscript? At broad level there are 3 kinds of operators as mentioned below. Arithmetic Operators Comparison Operators Logical Operators Arithmetic Operators in the order of pre… Read More
  • Date time functions in vb script Date time functions in vb script It is very important that you know how to work with date and time in VBScript as most of the VBScript programs will have date and time involved in it.Below is the list of all date and … Read More
  • Error handling in VBScript Error handling in VBScript VBScript provides below statements and keywords to handle errors. on error resume next Err object - err.description, err.number Sample code to handle the error is given below If er… 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

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

150,595

Blog Archive