Sgn

The Sgn function takes any number as its argument, and returns an integer. It is used to determine the sign of a number. If you send the function a negative number, it returns a -1, if you send the function a positive number, it returns a 1, and if you send the function , it returns 0. An example of the function:
Private Sub cmdReturnSign_Click()
     Dim x As Double

     x = 2465
     lblSign.Caption = Sgn(x)     'This causes the caption to display 1

     x = -3.141592653589793238462643383279
     lblSign.Caption = Sgn(x)     'This causes the caption to display -1     

     x = 0
     lblSign.Caption = Sgn(x)     'This causes the caption to display 0
End Sub
This concept is useful outside of Visual Basic and Computer Science, and is also used by mathematicians. "Signum" can be used to make long, complicated equations less so.

Log in or register to write something here or to contact authors.