|
-
Jun 18th, 2000, 08:21 AM
#1
Thread Starter
Lively Member
Hi there,
I have 3 textboxes and a command button. When the button is clicked, the result of text2 divided by text1 appears in text3.
Decimals are not allowed - has to be fractions or whole numbers. I've got it working pretty well:
Private Sub Command1_Click()
If Text1 Mod Text2 > 0 Then
Text3 = Text1 & "/" & Text2
Else:
Text3 = Text1 / Text2
End If
End Sub
However, how can I have it so that the answer is simplified? For example, 12 in text1 and 8 in text2 will give 12/8 in text3, but it would be so much better if it simplified it automatically to 3/2.
Any ideas?
Thanks for any help
-
Jun 18th, 2000, 08:37 AM
#2
Addicted Member
Hi,
For No Decimals Try: "\"
Text3 = Text1 & "\" & Text2
Sorry about the fractions!
Good Luck.
-
Jun 18th, 2000, 09:07 AM
#3
try this
Code:
Dim text1 As Integer, text2 As Integer, i As Integer, HighDivNumber As Integer
'since we know text1 will be bigger than text2 this is how to do it
'you will need to write your own statement to make sure text1 is bigger
text1.Text = text1
text2.Text = text2
For i = 1 To text2
If (text1 Mod i) = 0 And (text2 Mod i) = 0 Then
HighDivNumber = i
End If
Next i
text1 = text1 / HighDivNumber
text2 = text2 / HighDivNumber
'now put these numbers in your 3rd text box
I haven't verified if it works, but I think it will.
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
|