January 29th, 2000, 03:30 PM
i made a VB code that would find the LCM between two numbers. Here it is
public Function Math_LCM(n1 as Double, n2 as Double) as Double
LCM = n1 * n2
n0 = n1 * n2
x = 2
Do: DoEvents
n1 = (n1 / (x - 1)) * x
If Math_IsInteger(n1 / n2) then LCM = n1: Exit Do
x = x + 1
Loop Until n1 = n0
Math_LCM = LCM
End Function
It worked when I used it alone. I did 3, 5 - it gave back 15. 2, 4 - it gave back 4. Anyway, then I tried to make VB code that would simplify a fraction. Here is what I got:
public Function Math_Simplify(numerator as Double, denominator as Double) as string
If Not Math_IsInteger(numerator) then Exit Function
If Not Math_IsInteger(denominator) then Exit Function
n = Val(numerator)
d = denominator
n0 = Math_LCM(n, d)
x = n0 / n
n = n * x
d = d * x
Math_Simplify = Trim(Str(n)) + "/" + Trim(Str(d))
End Function
Before I go on, Math_IsInteger(x) checks if x is an integer by using the Fix() function. Anyway, I keep getting the error 'ByRef Argument Type Mismatch' - and VB5 highlights the "n" in the line of code:
n0 = Math_LCM(n, d)
I don't understand it...Can you help me?
public Function Math_LCM(n1 as Double, n2 as Double) as Double
LCM = n1 * n2
n0 = n1 * n2
x = 2
Do: DoEvents
n1 = (n1 / (x - 1)) * x
If Math_IsInteger(n1 / n2) then LCM = n1: Exit Do
x = x + 1
Loop Until n1 = n0
Math_LCM = LCM
End Function
It worked when I used it alone. I did 3, 5 - it gave back 15. 2, 4 - it gave back 4. Anyway, then I tried to make VB code that would simplify a fraction. Here is what I got:
public Function Math_Simplify(numerator as Double, denominator as Double) as string
If Not Math_IsInteger(numerator) then Exit Function
If Not Math_IsInteger(denominator) then Exit Function
n = Val(numerator)
d = denominator
n0 = Math_LCM(n, d)
x = n0 / n
n = n * x
d = d * x
Math_Simplify = Trim(Str(n)) + "/" + Trim(Str(d))
End Function
Before I go on, Math_IsInteger(x) checks if x is an integer by using the Fix() function. Anyway, I keep getting the error 'ByRef Argument Type Mismatch' - and VB5 highlights the "n" in the line of code:
n0 = Math_LCM(n, d)
I don't understand it...Can you help me?