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. See the last post for the latest version.

### 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

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.

### 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:

Catch
Message(Error.Text)

That will prevent the program from crashing when the numbers

are entered incorrectly.

### Re: Fractions Caculator

Posted: **Tuesday 15th October 2019 3:27am**

by **cage**

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

### Re: Fractions Caculator

Posted: **Thursday 17th October 2019 3:38pm**

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?

### Re: Fractions Caculator

Posted: **Friday 18th October 2019 4:19am**

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.

### Re: Fractions Caculator

Posted: **Sunday 20th October 2019 9:46pm**

by **cage**

Here is the new version of the calculator program. Fixed the problems and one I overlooked and did some rework on the GUI