Fractions Caculator

Post Reply
cage
Posts: 35
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 34 times

User avatar
cogier
Site Admin
Posts: 349
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 25 times

cage
Posts: 35
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: 35
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.

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

Re: Fractions Caculator

Post by cage » Tuesday 15th October 2019 3:27am

With the advent of Gambas 3.14 the fractions calulator no longer works. I am in the process of finding out why.

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

Re: Fractions Caculator

Post by cogier » Thursday 17th October 2019 3:38pm

I have run the program in 3.14 and it seems OK to me. Is there a particular input that will crash the code?

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

Re: Fractions Caculator

Post by cage » Friday 18th October 2019 4:19am

For some reason it would only display the fractions after clicking on enter. I have fixed the problem and now all I need to do is put together instructions on how to use it. Should be posting the newer version in the next few days. It may be a problem with the way Arch handles the Gambas programs don't know for sure. I never ran these kind of problems while I was running Kubuntu 18.04.

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

Re: Fractions Caculator

Post by cage » Sunday 20th October 2019 9:46pm

Here is the new version of the calculator program. Fixed the problems and one I overlooked and did some rework on the GUI
Attachments
FracCalculator_V3_3.tar.gz
(58.73 KiB) Downloaded 7 times

Post Reply