# Improper Fractions to Proper Fractions

Page 1 of 1

## 3 Replies - 1417 Views - Last Post: 13 October 2009 - 03:01 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=131796&amp;s=e009b3f91a8d3e5840b189edc23893e7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Muchini

Reputation: 0
• Posts: 1
• Joined: 13-October 09

# Improper Fractions to Proper Fractions

Posted 13 October 2009 - 10:57 AM

```Public Class Form1
Dim intResNum, intResDenom As Integer
Private Sub btnMult_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMult.Click
Dim intF1Num, intF2Num, intF1Denom, intF2Denom As Integer
intF1Num = CInt(TextBox1.Text)
intF1Denom = CInt(TextBox2.Text)
intF2Num = CInt(TextBox3.Text)
intF2Denom = CInt(TextBox4.Text)
intResNum = intF1Num * intF2Num
intResDenom = intF1Denom * intF2Denom
TextBox5.Text = intResNum.ToString
TextBox6.Text = intResDenom.ToString
End Sub

Private Sub btnDiv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDiv.Click
Dim intF1Num, intF2Num, intF1Denom, intF2Denom As Integer
intF1Num = CInt(TextBox1.Text)
intF1Denom = CInt(TextBox2.Text)
intF2Num = CInt(TextBox3.Text)
intF2Denom = CInt(TextBox4.Text)
intResNum = intF1Num * intF2Denom
intResDenom = intF1Denom * intF2Num
TextBox5.Text = intResNum.ToString
TextBox6.Text = intResDenom.ToString
End Sub

Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim intF1Num, intF2Num, intF1Denom, intF2Denom, intCD As Integer
intF1Num = CInt(TextBox1.Text)
intF1Denom = CInt(TextBox2.Text)
intF2Num = CInt(TextBox3.Text)
intF2Denom = CInt(TextBox4.Text)
intCD = intF1Denom * intF2Denom
intResNum = (intF1Num * intF2Denom) + (intF2Num * intF1Denom)
intResDenom = intCD
TextBox5.Text = intResNum.ToString
TextBox6.Text = intResDenom.ToString
End Sub

Private Sub btnSub_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSub.Click
Dim intF1Num, intF2Num, intF1Denom, intF2Denom, intCD As Integer
intF1Num = CInt(TextBox1.Text)
intF1Denom = CInt(TextBox2.Text)
intF2Num = CInt(TextBox3.Text)
intF2Denom = CInt(TextBox4.Text)
intCD = intF1Denom * intF2Denom
intResNum = (intF1Num * intF2Denom) - (intF2Num * intF1Denom)
intResDenom = intCD
TextBox5.Text = CStr(intResNum.ToString)
TextBox6.Text = CStr(intResDenom.ToString)
End Sub

Function GCD(ByVal M As Integer, ByVal N As Integer) As Integer
'return the positive GCD (greatest common divisor) of two numbers M, N
'follows algorithm recorded by Euclid in approx 300 BC
Dim r As Integer
M = Math.Abs(M) 'convert to positive numbers to avoid issues with remainders
N = Math.Abs(N)
If M = 0 Or N = 0 Then
Return 1
End If
'The following lines are not required, but might make the algorithm clearer to understand
'If M < N Then 'make M the bigger number
'	r = M
'	M = N
'	N = r
'End If
Do
r = M Mod N 'remainder of dividing M by N
M = N 'transfer
N = r
Loop While r <> 0 'repeat loop if r not equal to 0, otherwise exit this loop (go to next line)
'At this point we are out of the loop, and M will hold the correct result
Return M
End Function

Private Sub btnSimp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSimp.Click
Dim G As Integer
G = GCD(intResNum, intResDenom)
intResNum = intResNum / G
intResDenom = intResDenom / G
txtSimp1.Text = intResNum.ToString
txtSimp2.Text = intResDenom.ToString

End Sub

Private Sub btnProper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProper.Click
NEED HELP HERE

End Sub
End Class
```

Mod Edit: When you are posting code please use code tags like this.

Is This A Good Question/Topic? 0

Reputation:

## Re: Improper Fractions to Proper Fractions

Posted 13 October 2009 - 11:33 AM

It's impossible to convert improper fraction to a proper fraction. You can, however, convert it into a mixed fraction.

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

## Re: Improper Fractions to Proper Fractions

Posted 13 October 2009 - 01:25 PM

This is vb.net code not vb6.

### #4 dzone41

Reputation: 46
• Posts: 218
• Joined: 21-August 09

## Re: Improper Fractions to Proper Fractions

Posted 13 October 2009 - 03:01 PM

You are using all Integer data types....may want to look into another numerical data type when working with fractions

This post has been edited by dzone41: 13 October 2009 - 03:04 PM