Fraction code completed Part 1 | Member | | Join Date: Nov 2007 Location: Iowa
Posts: 38
| |
Hi All For those of you that helped me with the questions on this... Thank you! I believe I have solved all the bugs in the code and wanted to post the final product. This is a set of code to solve basic frational arithmatic. using only 3 textboxes. Allowing the user to enter any type of fraction and get a proper reduced fraction answer. Feel Free to use it if you like it. Had to do 2 posts sorry was too long I guess.
Parameters:
VB.Net code
single form with 3 textboxes named:
textbox1
textbox2
textbox3
4 buttons named:
Addfract
Subfract
Multifract
DivFract
(Clear button optional)
and function using Euclid's algorithm (included in post)
Uses Try/Catch to handle user imput errors -
' Returns the greatest common divisor using Euclid's algorithm
-
Private Function GCD(ByVal x As Integer, ByVal y As Integer) As Integer
-
Dim temp As Integer
-
-
x = Math.Abs(x)
-
y = Math.Abs(y)
-
-
Do While (y <> 0)
-
temp = x Mod y
-
x = y
-
y = temp
-
Loop
-
-
Return x
-
End Function
-
Hope you find it usefull,
James
|  | Site Moderator | | Join Date: Jan 2007 Location: America
Posts: 3,393
| | | re: Fraction code completed Part 1
Adding CODE tags makes this post disappear.
|  | Moderator | | Join Date: Nov 2006 Location: Richmond, Virginia USA
Posts: 3,002
| | | re: Fraction code completed Part 1
I'm an old DOS programmer, and as I've stated before, don't know diddly about programming websites, but I just had to fiddle with this thing! What I found out was that, indeed, if you hilite all the code and apply code tags to it, the post disappears. If, however, you hilite one sub/function at a time and apply code tags to it, everything worked just fine!
Linq ;0)> BTW: Where I come from, Dim statements are supposed to be at the beginning of a sub/function, not interspersed throughout. If this is going to be an article, we really should stick to best practises, shouldn't we?
|  | Site Moderator | | Join Date: Jan 2007 Location: America
Posts: 3,393
| | | re: Fraction code completed Part 1 Quote:
Originally Posted by missinglinq BTW: Where I come from, Dim statements are supposed to be at the beginning of a sub/function, not interspersed throughout. If this is going to be an article, we really should stick to best practises, shouldn't we? If you say so, I've never written a line of VB code in my life.
| | Member | | Join Date: Nov 2007 Location: Iowa
Posts: 38
| | | re: Fraction code completed Part 1
Ok guys thanks well heres the rest of the code.
The moderators made a good point about the dims So I will try to clean up and shorten the code and post it in part 2
|  | Similar .NET Framework bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|