Sgn Function

See AlsoC6AIPK              Example103LYZ2>Low

Returns an integer indicating the sign of a number.




The argument number can be any valid numeric expression71RISN.  Its sign determines the value returned by the Sgn function:

         If number > 0, then Sgn(number) returns 1.

         If number = 0, then Sgn(number) returns 0.

         If number < 0, then Sgn(number) returns -1.

See Also

Math FunctionsEK0VY1

Sgn Function Example

The example uses Sgn to determine the sign of a number.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim Msg, Number                             ' Declare variables.

   Number = InputBox("Enter a number.")        ' Get user input.

   Select Case Sgn(Number)                     ' Evaluate user input.

      Case 0                                   ' Zero.

         Msg = "You entered zero."

      Case 1                                   ' Positive.

         Msg = "You entered a positive number."

      Case -1                                  ' Negative.

         Msg = "You entered a negative number."

   End Select

   MsgBox Msg                                  ' Display results.

End Sub