3 Replies - 975 Views - Last Post: 13 October 2009 - 03:01 PM Rate Topic: -----

#1 Muchini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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. :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Improper Fractions to Proper Fractions

#2 Guest_Neumann*


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.
Was This Post Helpful? 0

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2270
  • View blog
  • Posts: 9,496
  • Joined: 29-May 08

Re: Improper Fractions to Proper Fractions

Posted 13 October 2009 - 01:25 PM

This is vb.net code not vb6.
Was This Post Helpful? 0
  • +
  • -

#4 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1