|
-
Sep 15th, 2000, 06:34 AM
#1
Hi! I have two picture boxes and two command buttons. Command1 gives two random numbers in Picture1, fractions, like:
7/2 or 12/4 or 29/14
Then, when command2 is clicked, the fraction is simplified in Picture2.
7/2 would become 3 1/2, 12/4 becomes 3, 29/14 becomes 2 1/29
etc....
My code works fine when I have it in command1 and command2 like this:
Dim numer As Integer
Dim denom As Integer
Private Sub Command1_Click()
Randomize
numer = Int(Rnd * 30) + 1
denom = Int(Rnd * 10) + 1
Picture1.Cls
Picture1.Print numer & "/" & denom
End Sub
Private Sub Command2_Click()
Picture2.Cls
Dim lowestfraction As String
If numer Mod denom <> 0 Then
lowestfraction = IIf(Int(numer / denom) > 0, Int(numer / denom), "") & " " & numer Mod denom & "/" & denom
End If
If numer Mod denom = 0 Then
lowestfraction = numer / denom
End If
Picture2.Print lowestfraction
End Sub
But I want the code in command2 to be a function that I can call throughout my project. All it returns is '0'.
Anybody got any ideas, please? This is the way I have my code:
Private Sub Command1_Click()
Randomize
numer = Int(Rnd * 30) + 1
denom = Int(Rnd * 10) + 1
Picture1.Cls
Picture1.Print numer & "/" & denom
End Sub
Private Sub Command2_Click()
Picture2.Cls
Picture2.Print ReduceFractions(numer, denom)
End Sub
Public Function ReduceFractions(ByVal upper As Integer, ByVal lower As Integer) As Integer
Dim lowestfraction As String
If upper Mod lower <> 0 Then
lowestfraction = IIf(Int(upper / lower) > 0, Int(upper / lower), "") & " " & upper Mod lower & "/" & lower
End If
If upper Mod lower = 0 Then
lowestfraction = upper / lower
End If
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|