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:
Private Function AddNumberRange(ByVal lngStart As Long, ByVal lngFinish As Long) As Long AddNums = ((((lngFinish^ 2) - ((lngStart ^ 2)) + lngFinish + (lngStart) / 2) End Function
Example: AddNums(1, 100) ' 5050
-----------------------------------------------------------------------------
Name: Compute Nth root of a number
VB Code:
Private Function NthRoot(ByVal lngRoot, ByVal lngNumber) As Double NthRoot = (lngNumber ^ (1 / lngRoot)) End Function
Example: NthRoot(13, 8192) ' Prints 2 (13th root of 8192)
-----------------------------------------------------------------------------
Name: Convert Radians to Degrees:
VB Code:
Private Function Rad2Deg(ByVal dblRadians As Double) As Double Rad2Deg = dblRadians * 180 / 3.14159265358979323846 End Function
-----------------------------------------------------------------------------
Name: Convert Degrees to Radians:
VB Code:
Private Function Deg2Rad(ByVal dblDegrees As Double) As Double Deg2Rad = dblDegrees * 3.14159265358979323846 / 180 End Function
-----------------------------------------------------------------------------
Name: Return Fractional Part Of a Number
VB Code:
Private Function ReturnFraction(ByVal dblNumber As Double) As Double Dim intTempVal As Integer intTempVal = dblNumber \ 1 ReturnFraction = dblNumber - intTempVal End Function
Example: ReturnFraction(1.2345) ' Returns 0.2345
-----------------------------------------------------------------------------
Name: Return a factorial of a number.
VB Code:
Private Function Factorial(ByVal intNumber As Integer) As Long If intNumber <> 1 Then Factorial = (intNumber * Factorial(intNumber - 1)) Else Factorial = 1 End If End Function
Example: Factorial(5) ' Returns 120, 5*4*3*2*1 = 120
--------------------------------------------------------------------------
Cheers and hope those help someone
RyanJ





Reply With Quote