Fractions Caculator

Post Reply
cage
Posts: 9
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Fractions Caculator

Post by cage » Thursday 05th September 2019 6:55pm

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.
FracCalculator_V3_2.tar.gz
Fractions Calculator
(68.97 KiB) Downloaded 10 times

User avatar
cogier
Site Admin
Posts: 302
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Fractions Caculator

Post by cogier » Friday 06th September 2019 3:51pm

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

or
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
To
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.
FracCalculator_V3_2CO.tar.gz
(26.8 KiB) Downloaded 4 times

cage
Posts: 9
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post by cage » Friday 06th September 2019 6:43pm

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.

cage
Posts: 9
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post by cage » Sunday 08th September 2019 7:47pm

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:
Catch 
    Message(Error.Text)
That will prevent the program from crashing when the numbers
are entered incorrectly.

Post Reply