Results 1 to 5 of 5

Thread: VB - Some new Math Functions

Threaded View

  1. #1

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    VB - Some new Math Functions

    I love Maths, in a calculator script I wrote a while ago I used these, someone may find them useful

    General Functions:

    Name: Add a number range

    VB Code:
    1. Private Function AddNumberRange(ByVal lngStart As Long, ByVal lngFinish As Long) As Long
    2.     AddNums = ((((lngFinish^ 2) - ((lngStart ^ 2)) + lngFinish + (lngStart) / 2)
    3. End Function

    Example: AddNums(1, 100) ' 5050

    -----------------------------------------------------------------------------
    Name: Compute Nth root of a number

    VB Code:
    1. Private Function NthRoot(ByVal lngRoot, ByVal lngNumber) As Double
    2.     NthRoot = (lngNumber ^ (1 / lngRoot))
    3. End Function

    Example: NthRoot(13, 8192) ' Prints 2 (13th root of 8192)

    -----------------------------------------------------------------------------
    Name: Convert Radians to Degrees:

    VB Code:
    1. Private Function Rad2Deg(ByVal dblRadians As Double) As Double
    2.     Rad2Deg = dblRadians * 180 / 3.14159265358979323846
    3. End Function

    -----------------------------------------------------------------------------
    Name: Convert Degrees to Radians:

    VB Code:
    1. Private Function Deg2Rad(ByVal dblDegrees As Double) As Double
    2.     Deg2Rad = dblDegrees * 3.14159265358979323846 / 180
    3. End Function

    -----------------------------------------------------------------------------
    Name: Return Fractional Part Of a Number

    VB Code:
    1. Private Function ReturnFraction(ByVal dblNumber As Double) As Double
    2.     Dim intTempVal As Integer
    3.     intTempVal = dblNumber \ 1
    4.     ReturnFraction = dblNumber - intTempVal
    5. End Function

    Example: ReturnFraction(1.2345) ' Returns 0.2345

    -----------------------------------------------------------------------------
    Name: Return a factorial of a number.

    VB Code:
    1. Private Function Factorial(ByVal intNumber As Integer) As Long
    2.     If intNumber <> 1 Then
    3.         Factorial = (intNumber * Factorial(intNumber - 1))
    4.     Else
    5.         Factorial = 1
    6.     End If
    7. End Function

    Example: Factorial(5) ' Returns 120, 5*4*3*2*1 = 120

    --------------------------------------------------------------------------

    Cheers and hope those help someone

    RyanJ
    Last edited by sciguyryan; May 25th, 2005 at 02:43 PM.
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width