Share My Creation Tape calculator

Attached you find a small kind of paper tape calculator that memorizes the different operations.
This was my first program in B4Android ported from B4PPC.
It uses one Togglebutton with user defined bitmaps added in the code.
Uses following libraries:
StringUtils (standard)
AHLocale (additional)

Best regards.

EDIT: 2012.11.26
Updated the program, works also on tablets.

EDIT: 2013.06.20 Version 1.4
Added landscape mode, with no loss of calculation.
Added multilanguage, currently en, fr, de
The language files are in the File.DirRootExternal/TapeCalc folder.
To add a new language you can translate one of the existing files and add it to the File.DirRootExternal/TapeCalc folder.
The device default language is checked and if a file for this language does exist it is loaded otherwise the english file is loaded.
The files are tapecalc_xx.txt, xx = 2 character international code like en, fr, de
 

Attachments

  • TapeCalc.jpg
    TapeCalc.jpg
    34.5 KB · Views: 21,753
  • TapeCalcV1_4.zip
    14 KB · Views: 1,796
Last edited:

CSP

Member
Licensed User
Longtime User
Hey Klaus, nice work as always, EXCEPT, type in .001 + .001 equals, then type it again or another decimal and there is a problem. However, the fix is very simple;

Change this:
If b="0" OR b="1" OR b="2" OR b="3" OR b="4" OR b="5" OR b="6" OR b="7" OR b="8" OR b="9" OR b="3.1415926535897932" Then

To this:
If b="." or b="0" OR b="1" OR b="2" OR b="3" OR b="4" OR b="5" OR b="6" OR b="7" OR b="8" OR b="9" OR b="3.1415926535897932" Then
If b = "." AND sVal.Contains(".") = True Then Return '<-- add this line too

Thanks again for everyone's many contributions to the B4A community!
 
Last edited:

GMan

Well-Known Member
Licensed User
Longtime User
Grüetzi Klaus,

how can i implement this calculator in a tabhost ?
i tried it, but in the part
B4X:
Sub UpdateTape
   Dim hcalc As Float
   
   lblPaperRoll.Text = Txt

   hcalc = stu.MeasureMultilineTextHeight(lblPaperRoll, Txt) 
   stu.MeasureMultilineTextHeight(lblPaperRoll, Txt)
   If hcalc > scvPaperRoll.Height Then
      lblPaperRoll.Height = hcalc 
      scvPaperRoll.Panel.Height = hcalc
      DoEvents
      scvPaperRoll.ScrollPosition = hcalc
   End If
End Sub

causes some errors.
 

GMan

Well-Known Member
Licensed User
Longtime User
Here is some code so far (TabHost_Changed event):

B4X:
   If  KnowHowTabHost.CurrentTab = 2 Then

    Try
   Activity.RemoveView 
   Activity.LoadLayout("tapecalc")  
   Activity.BringToFront 
    Catch As Exception 
    End Try
   

   lblPaperRoll.Initialize("lblPaperRoll")
'   scvPaperRoll.Panel.AddView(lblPaperRoll, 0, 0, 100%x, scvPaperRoll.Height)
'   scvPaperRoll.Panel.Height = scvPaperRoll.Height
   lblPaperRoll.TextSize = 22 * ScaleAuto
   lblPaperRoll.Color = Colors.White
   lblPaperRoll.TextColor = Colors.Black
   
   imgCharSizeDown.Initialize(File.DirAssets, "btnCharSizeDown.bmp")    
   imgCharSizeUp.Initialize(File.DirAssets, "btnCharSizeUp.bmp")    

   bd1.Initialize(imgCharSizeUp)
   bd2.Initialize(imgCharSizeDown)
   sd.Initialize
   Dim states(2) As Int
   states(0) = sd.state_unchecked
   states(1) = -sd.state_checked
   sd.addState2(states, bd1)
   Dim states(1) As Int
   states(0) = sd.state_checked
   sd.addState2(states, bd2)
   btnCharSize.Background = sd
   
      
   
   Dim clv3 As CustomListView
   clv3.Initialize(Me, "clv3")
   clv3.DefaultTextBackgroundColor = Colors.Black
   CalcPanel.AddView(clv3.AsView, 0, 0, CalcPanel.Width, CalcPanel.Height)
   
   End If
 

klaus

Expert
Licensed User
Longtime User
Sorry, but with only the code snippet you post impossible to find out what you really want to do and how.
- Is the code snippet all what is in the TabHost_Changed event?
- You speak about a TabHost, I don't see any reference to a TabHost, where is it ?
- What is CalcPanel ?
- What does the CustomListView do ?
- Why do you load the tapecalc layout onto the Activity ?
- What error do you get ?
- What is Activity_RemoveView supposed to do ?

So you see lots of questions. And I still don't know what you are trying to do.
When you post a question or have a problem try once to take the place of a helper and ask yourself the question :
Do these guys have the information they need to help !!!
Just a few seperate code snippets are not sufficient (at least for me).

Best regards.
 
Last edited:

JakeBullet70

Well-Known Member
Licensed User
Longtime User
portrait & landscape mode now supported

I went ahead and re-scaled the calc, now works in both portrait & landscape and stretches out to fill the whole screen

Thanks klaus.

have fun all!!!!

Enjoy
 

Attachments

  • l1.jpg
    l1.jpg
    68.9 KB · Views: 593
  • l2.jpg
    l2.jpg
    69.5 KB · Views: 652
  • TapeCalcXY.zip
    19.1 KB · Views: 655

klaus

Expert
Licensed User
Longtime User
I had a look at your code.
Some remarks:
- When changing the orientation all data are lost !
- On a big (10'') screen the numbers in the buttons are too small.
- You could have used one layout file with two variants instead of two.
In your case the layout is the same and you align the views in the DesignerScript, this can be done with variants.

In my mind a tape calculator is in portrait that's why I didn't even provide a landscape layout.
But your aproach is interesting.

Best regards.
 

Beja

Expert
Licensed User
Longtime User
Thank you Klaus for your crusade to help us. I personally appreciate and recognize your great samples the help all of us understand this language.
This app is very helpful specially when shopping, for shoppers and traders.

My wish:
If you could automate Google's Translation and incorporate that within the
calc interface then this app could be a very successful commercial package.
(Advice from professional traveler).
 

Theera

Well-Known Member
Licensed User
Longtime User
Hi Klaus,
I need some example to use it. I think that it 's useful for me.

Best Regards
Theera
 

klaus

Expert
Licensed User
Longtime User
I need some example to use it.
What kind of examles are you expecting.
Currently it's a stand alone program.
In a near future I will make a class out of it.

The RPNCalculator program does already exist as a class and library.

Best regards.
 

GMan

Well-Known Member
Licensed User
Longtime User
In a near future I will make a class out of it.

So i will wait for the class, too, 'cause i also can't get it work in my TabPanel.
 

bodycode

Member
Licensed User
Longtime User
Klaus, I want to take what is displayed in the "answer", which I really don't know where it is, and then use the answer output in other applications, throughout other subs and modules. I can't seem to find a place to do this because I don't know which variable is used to hold the answer. is this possible?

Thank in advance.

Regards, bodycode, license user.



This was my first program in B4Android ported from B4PPC.
It uses one Togglebutton with user defined bitmaps added in the code.
 

bodycode

Member
Licensed User
Longtime User
What I mean, is the display value, not the "answer". Correction.
 

klaus

Expert
Licensed User
Longtime User
You have two ways to get the answer:
TapeCalc1.Initialize(Me, "TapeCalc1")

and then
- TapeCalc1.Show(edtTest) returns the result in the object transmitted, in the example the edtTest EditText object.
- TapeCalc1.Show(Null), in this case you should add following event routine in your code :
Sub TapeCalc1_Closed(Result As Double)
' your code
End Sub


If you want the whole display then you must change in the class:
Private lblPaperRoll As Label
to
Public lblPaperRoll As Label
to make it accessible from outsides.

Best regards.
 
Top