Android Question Klaus Calculator

Shelby

Active Member
Licensed User
https://www.b4x.com/android/forum/threads/anyone-created-a-simple-calculator.16314/

When I try to run the debug on the above calculator I find that a library is missing according to a popup message. Is there a way I can get that missing library? Also I get the following error when I run debug on the code.

B4X:
B4A Version: 9.00
Parsing code.    Error
Error parsing program.
Error description: Unknown type: ahlocale
Are you missing a library reference?
Error occurred on line: 55 (Main)
Dim Locale As AHLocale

I don't understand this error. Primarily this question is directed to Klaus but anyone's reply is appreciated. My first and only App is a calculator and I'm trying to make sense of it all.
 

AnandGupta

Well-Known Member
Licensed User
Hi Shelbrain,

I understand you are too busy with work, so you have very little time to read message from members and follow it.
I am lending my helping hand with below image from your message.

Hope it helps you.

2019-04-13_000832.png


Regards,

Anand
 
Upvote 0

Shelby

Active Member
Licensed User
Sorry, at message 16 I was rushing around preparing to leave and didn't have time to address that suggestion of wrong code. I'm off early now and will view all suggestions.
Thanks
 
Upvote 0

Shelby

Active Member
Licensed User
Here's the zip file with the Klaus calculator as I'm trying to operate it.
 

Attachments

  • Klaus_calculator_project.zip
    191.1 KB · Views: 78
Upvote 0

Shelby

Active Member
Licensed User
Klaus,
What I'm trying to do is learn how to code a container to save each module's calculation to move on to the next room. I thought I could get some insight from the Klaus calculator. Markus and Emexes gave me some help a couple of weeks ago but I don't know exactly how to use their suggestions.
 
Upvote 0

Shelby

Active Member
Licensed User
Here's my project in progress. My intention is for a user to calculate a room's area and then move on to the next room (or module in my code) and calculate the succeeding rooms until the building is completed. I'm in no rush and hope to understand how everything works not just get the project completed, etc.
I'm on page 566 of the Seagrave book. I listen to many questions in the forum daily.
 

Attachments

  • Shelby_Area_calculator.zip
    498.9 KB · Views: 76
Upvote 0

Shelby

Active Member
Licensed User
Thanks Anand,
The quotations marks were a help. Now this message:

B4X:
java.io.FileNotFoundException: /storage/emulated/0/TapeCalc/tapecalc_en.txt (No such file or directory)

I have the file in the file manager list. I suppose I must get the configuration correct. Hmm, I removed the tapecalc_en.txt and added it from my B4A project folder and still the debug is bugged.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
It had a close look at your project, there were different problems.

1. The quotes were missing.

2. You changed this line from the original program :
If FileName.Length >= 15 And FileName.ToLowerCase.SubString2(0, 9) = "tapecalc_" And File.Exists(ProgPath, FileName) = False Then
into this one :
If FileName.Length >= 15 And FileName.ToLowerCase.SubString2(0, 9) = "tapecalc_en" And File.Exists(ProgPath, FileName) = False Then
you added "en" and with this, the language files were never copied and therefore were missing.
I got he same error as you and was estonished why.
Then I put a breakpoint in the IDE, at the line above, and executed the program step by step and noticed that the language files existed but weren't copied, why.
Then I compared with the original and saw the differene, two extra characters.

3. The original program had the targuetSDKversion below 23.
You set it to 26, which means that you would have needed to add access permissions to access File.DirRootExternal, new Google rules.

4. I set the background of the Avtivity in the Designer to black.
The program was written quite some years ago when the default background color was black.
Google changes this with almost every new version.

As you want only english texts I removed all the multilanguage stuff.
No need for the AHLocale library, this was used to read the language setting of the device, not needed for you any more.
I removed the two library files from the projects Files folder. You should never add library files into this folder but in the AdditionalLibraries folder.
No need to read any text file. All the texts are hard coded, the relevant program lines were still in the origanal project as a reminder.
I removed the language files from the projects Files folder.

It was frustrating for me that I had to write some unpleasent comments to make you react.

So, now you got a solution to your problem and not only an answer to a question!
This thread is a good example illustrating why we helpers often:
- Ask what exactly the PROBLEM is and not just trying to answer a question.
- Ask that you upload the project or small project showing the problem.
Very often, the problem is not where you think it is but it somewhere else.
Without the project I wouldn't have found the problems.

Have you ever read this thread: How to ask a question?
Or read this chapter Ask a question in the forum in the B4X Booklets?

And at the end a good point.
You tried first to modify the project on your own before asking for help. This is the right aproach.

Attached you find the modified project.
 

Attachments

  • Klaus_calculator_project_New.zip
    172.7 KB · Views: 75
Upvote 0

klaus

Expert
Licensed User
I had a look at your project.

My comments about the code:

1. I wouldn’t use any calculator, I would do as you do it right now calculate it in the program.

2. I wouldn’t use a new Activity for each room, these are almost all the same with the same layout and the same code. This would be very difficult to maintain.
Use one screen for all rooms and update the content of the different views according to the current room.
Currently, Room4, Room5, Room6 are exactly the same.
Note, that a layout is not linked to an Activity nor a Panel, they are independent.
That means, that you can load the same layout file on different Activities or Panels.

3. I would use a Type variable like with the length, the width and the area:
Type Rooms(Length As Double, Width As Double, Area As Double)
Use a List with the data of all the rooms. With a List you can add, modify or remove items.
Add a ListView with the summary of all data which allows to select rooms.
And the button to add a room and the button to calculate.

4. It could be interesting to also display the total area.

5. What about rooms which are not rectangular?
You could add room types with different shapes.

Comments about the layouts.

1. You need to learn how anchors work, some view have anchors others no, both, or right.
Example: Room1 (why do you have an underscore at the end of the layout file names?)
lblFind: anchor BOTH
lblTitle: anchor LEFT
lblResult: anchor RIGHT
Looks not coherent to me.

2. You have overlapping views, why? Example: lblWidth and edtWidth.

3. You have views outsides the screen size !? Example: lblNext.
You may perhaps set its anchor to BOTTOM.

4. You use a Label to move to the next room. Why don’t you use a Button?

5. The landscape layouts are not (yet) looking good.
 
Last edited:
Upvote 0

Shelby

Active Member
Licensed User
Thanks for your critique. I greatly appreciate your knowledge and dedication to the B4 languages. I'll be trying to put your suggestions into action.
Shelb
 
Upvote 0

Shelby

Active Member
Licensed User
In your calculator project I changed the file name from "tapecalc_de" to "tapecalc_en" because in my files manager, all three (German, French and English) files were there. I thought that it might be a simple use of any one of the three and my German is limited; i.e. "Ich bin ein scheisskopf". I didn't know there were supporting files which had to be added, etc.




Now for addressing your input about my AreaApp.....


2. I wouldn’t use a new Activity for each room,
Use one screen for all rooms and update the content of the different views according to the current room. I don't know how to do this but I'll research it. Months ago I searched and found that you or Erel had suggested using modules to move from page to page so I happily created what I have, using modules. https://www.b4x.com/android/forum/threads/multiple-pages-example.48170/#content
Currently, Room4, Room5, Room6 are exactly the same.
Note, that a layout is not linked to an Activity nor a Panel, they are independent.
That means, that you can load the same layout file on different Activities or Panels. O.K.-Thanks for that tip.

3. I would use a Type variable like with the length, the width and the area:
Type Rooms(Length As Double, Width As Double, Area As Double)
Use a List with the data of all the rooms. With a List you can add, modify or remove items. I don't know how to do that but I'll research it.
Add a ListView with the summary of all data which allows to select rooms. Ha, I'll be lost for days or weeks trying to understand that but I'll try.
And the button to add a room and the button to calculate. These are easily changed, thanks.

4. It could be interesting to also display the total area. Yes that is my intention for each new page/room.

5. What about rooms which are not rectangular? My knowledge of geometry will come into play in the future of this part of the project but on the back burner as we say.
You could add room types with different shapes. Righto!

Comments about the layouts.

1. You need to learn how anchors work, some view have anchors others no, both, or right. As I have checked the view of my phone or the emulator view I have noticed some slight differences so I moved the buttons, views, and labels in order to give the result I have wanted but not having any knowledge of why the anchor arrows might be important to stop some outcome as you suggest.
Example: Room1 (why do you have an underscore at the end of the layout file names?) (I have 3 or 4 versions of this project to protect my original project from being corrupted by my potential errors. Being ignorant of any reuse of layouts I have changed ever so slightly the names in order to make sure I don't somehow accidentally mix them up.)
lblFind: anchor BOTH
lblTitle: anchor LEFT
lblResult: anchor RIGHT
Looks not coherent to me. At my level coherence is only a clouded goal.

2. You have overlapping views, why? Example: lblWidth and edtWidth. As I mentioned above I thought it was a solution to the unsatisfactory appearance of the phone or emulator or both.

3. You have views outsides the screen size !? Example: lblNext.
You may perhaps set its anchor to BOTTOM. O.K. Thanks

4. You use a Label to move to the next room. Why don’t you use a Button? O.K., That should be easily accomplished.

5. The landscape layouts are not (yet) looking good. Hey, that's my good buddy's art. I like it. (Who knows what I'll end up with though? It's just for my enjoyment as I work on this project. Ha)
I'm probably misunderstanding what you mean by landscape layouts. Maybe it's the landscape vs portrait concept.
Thanks again for your time and dedication. As you can see, I feel like a high school freshman in a class of university graduate students most of the time in this endeavor.
Shelbeaver
 
Last edited:
Upvote 0

Shelby

Active Member
Licensed User
Yay! I now have the Klaus Calculator project working with the post #30 zip file. I'll be analyzing how the changes you made were key to the successful operation of the code.
Thanks Klaus
 
Upvote 0

klaus

Expert
Licensed User
I played a bit with your project, adding some of my suggestions.
I have not tested everything, the purpose of the modified project is to show my vision of what your application could be and eventually give some ideas.
Up to you to undersatnd what I have done, how and even why.
Sorry, I am old fashioned, I like sober layouts without fancy graphics nor animations, but with the main data on one screen.
I know that most younger people are more concerned with graphics and animation rather than with the data. This might be generation conflict :).

I'm probably misunderstanding what you mean by landscape layouts.
You have two layout variants in the layout files, one for portrait and one for landscape. I was speaking about the landscape variants.
Turn your device and you'll see what I mean.
 

Attachments

  • AreaAppNew.zip
    485.2 KB · Views: 78
Last edited:
Upvote 0

Shelby

Active Member
Licensed User
Sorry, I am old fashioned, I like sober layouts without fancy graphics nor animations, but with the main data on one screen.

Ha ha,I guess you don't know I'm only 5 years your junior. I'm so old I can't snow ski anymore, (grumble grumble).

Much thanks again as always. As of now you and Amexes are my B4 heroes.
 
Upvote 0

klaus

Expert
Licensed User
Ha ha,I guess you don't know I'm only 5 years your junior.
No. I hadn't looked at your age.
So, we are at least two 'old fashioned' guys :).
 
Upvote 0
Top