Page 1 of 1

Fractions Caculator

Posted: Thursday 05th September 2019 6:55pm
by cage
Hi I am new to this forum and wanted to give to the community a program that I have written. It's a fractions calculator which I use in my wood working projects. It's a simple program to use. To use the first number or numbers will be the whole numbers. Once entered click on the Inch button to let the calculator know that a fraction follows. Enter the Numerator then the / button followed by the Denominator. Then click on one of the operator buttons Do the same as above for the second entry then click on the = button. If only calculating fractions just hit the Inch button with no entry then input the fraction for both first and second entries. Hope you find this little program useful.
Fractions Calculator
(68.97 KiB) Downloaded 11 times

Re: Fractions Caculator

Posted: Friday 06th September 2019 3:51pm
by cogier
Hi cage and welcome. I have had a look at your program and I have a few tips for you.
By grouping your buttons 0 to 9 I have managed to reduce 50 lines down to 3. See attached
There is no need to set Boolean values to False on starting your program as they are False by default.
You can declare the value of variables in one go. Variables of the same type can be declared in one line.
IsWholeNum As Boolean = True

Dim f, FirstFrac, SecondFrac As Float
  Dim D2F, ValueToConvert, DecPont, WholeNum As String
  Dim FindDecPoint, LengthOfVar As Integer
  Dim Numerator3 As Float = Numerator1
  Dim Numerator4 As Float = Numerator2
  Dim Denominator3 As Float = Denominator1
  Dim Denominator4 As Float = Denominator2

You can simplify: -
TextBox1.Text = TextBox1.Text & KeyNum
TextBox1.Text &= KeyNum
While I was trying to understand how to input things I crashed the program with the following key presses:
2 + [Inch] 2 =
I also changed the Form somewhat to make it expandable.
I hope it helps.
(26.8 KiB) Downloaded 5 times

Re: Fractions Caculator

Posted: Friday 06th September 2019 6:43pm
by cage
Thank You for your suggestions I will give it a try. As for crashing the program I should of put an error catch in the program. You normally would enter the 2 then hit [Inch] and then click on [+]. I will put a catch statement into the program to catch the error. I have been programming since 1982 which will tell you about how old I am. Most of the programming I did was with data bases. I am a self taught programmer. At one point I was a programmer in the aerospace industry and was the first programmer to work as such without a degree. Gambas is a great programming language how ever the lack of good documentation I think is what keeps it from being one of the top programming languages. Hopefully this board will change all that. I stumbled across this site and found it very useful so I joined up. I hope to contribute as much as I can to this board. Thank you for creating it.

Re: Fractions Caculator

Posted: Sunday 08th September 2019 7:47pm
by cage
I fixed the crashing error and you can fix it as follows.

At the end of the btnEquals sub find:
If Error Then Message( Error )
Replace it with:
That will prevent the program from crashing when the numbers
are entered incorrectly.