Sqr - VBScript


The Sqr command in VB Script calculates the square root of a specified numeric expression. It is commonly used to find the square root of numbers, particularly in mathematical and scientific applications.




  • number: Numeric expression whose square root is to be calculated.




Simple Example:

Dim x = 16
Dim squareRoot = Sqr(x)
' squareRoot now holds the value 4

Complex Example:

Sub CalculateDistance()
    Dim x1 = 2
    Dim y1 = 5
    Dim x2 = 10
    Dim y2 = 12

    Dim deltaX = x2 - x1
    Dim deltaY = y2 - y1
    Dim distance = Sqr(deltaX^2 + deltaY^2)
    ' distance now holds the Euclidean distance between points (x1, y1) and (x2, y2)
End Sub

Common Issues

  • If the input expression is negative, the result will be a complex number.
  • If the input expression is zero, the result will be zero.


The Sqr command can be combined with other mathematical functions, such as Math.Pow and Math.Abs, to perform more advanced calculations.

  • Math.Pow: Calculates the exponentiation of a number.
  • Math.Abs: Returns the absolute value of a number.