Fractions Caculator

So you have written that new, must have program. Let us see it here.
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Fractions Caculator

Post by cage »

Here is the latest version of my fractions calculator. I have changed the name to HandymanCalc with new features. I have added a multi document interface which now includes a conversion utility, and a conversion chart. Depending on your desktop and color scheme you may have to change the colors to your liking. I found that on Linux Lite if I added QT5 to the desktop the original colors worked fine. Charlie I have tried to post this on the farm but it won't except my login and password. If you could post it there I would greatly appreciate it. Also I finally found the divide by zero error and fixed it.
HandymanCalc.zip
(42.34 KiB) Downloaded 343 times
Last edited by cage on Friday 23rd October 2020 5:52pm, edited 8 times in total.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Fractions Caculator

Post 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

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 530 times
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post 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.
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post 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:
Catch 
    Message(Error.Text)
That will prevent the program from crashing when the numbers
are entered incorrectly.
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post by cage »

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: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Fractions Caculator

Post by cogier »

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: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post by cage »

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: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post by cage »

I have reworked the Fractions Calculator and made it easier to use. It uses a layout similar to the type of Fractions Calculator on a smart phone. Enjoy.
Last edited by cage on Sunday 18th October 2020 3:32am, edited 1 time in total.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Fractions Caculator

Post by cogier »

Hi cage,

Sorry but I think I have found a bug here. I was trying to divide ½ by ¼ and got this: -
The error occurs at line 427.

Image
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Fractions Caculator

Post by cage »

It's not a bug in the calculator as far as I can find. I will see what I can do to fix it. The default calculator doesn't even like it with small decimals dividing by another decimal. Example .50/.25 as you showed equals 2 and not .25. So that answer is not correct either. How ever with the same default calculator dividing .50 /2 will give you the answer of .25. So the correct way to divide 1/2 by 1/4 would be to divide 1/2 / 2 which will give you the answer of 1/4. Thanks for your input and trying out the calculator.
Post Reply