Android Question Storing My Calculations

Shelby

Well-Known Member
Licensed User
Longtime User
Hi All, Can you point me to the tutorial which tells me which storage object I should use to save my app's calculations? My app mathematically multiplies length times width and gives a Result. I'd like to save that result for adding it to the successive pages' results for a running total on each successive page.
Thanks
B4X:
Sub Globals
    'Variables always Private in this sub SSS
    Private Result As Double
    Private lblFind As Label
    Private lblResult As Label
    Private edtLen As EditText
    Private edtWidth As EditText
    Private btnCalc As Button
    Private pnlBitmap As Panel
 
    
    Private lblNext As Label
 
    Private lblTitle As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("math_layout")
    pnlBitmap.Initialize ("")
    Activity.AddView (pnlBitmap, 0%x, 270dip, 72%y, 190dip)
    Private bdwBitmap As BitmapDrawable
    bdwBitmap.Initialize(LoadBitmap(File.DirAssets, "Framing.jpg"))
    bdwBitmap.Gravity = Gravity.FILL
    pnlBitmap.Background = bdwBitmap
 
 
 
End Sub

Sub btnCalc_Click
    Result = edtLen.Text * edtWidth.Text
    lblResult.Text = Result & "     Square Feet"
    Log(Result & " Sq Ft")
End Sub


Sub lblNext_click
 
    StartActivity(Page2)
 
End Sub

'*******New idea for saving areas- but!... save in what receptacle?  Array? List?
Sub Save_Area
    Dim SvAry As Array
'or.........
    Dim SvLenandWid As List
    SvLenandWid.Initialize
 
 
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Last edited:

Shelby

Well-Known Member
Licensed User
Longtime User
Thanks to one of Erel's tutorials (written) I have 6 rooms in my project and look forward to using the variable i in some way to make the possible number of rooms infinite. Thanks to his tutorial I'm using modules for each room.
 
Last edited:
Upvote 0

Shelby

Well-Known Member
Licensed User
Longtime User
still firmly Imperial.
Yes imperialistically feet and inches. When I was in high school and college we were told that eventually we in America would adopt the far superior metric system. Our politicians (who else can I blame) have been dragging their scientific heels for who knows what reason.
 
Last edited:
Upvote 0

Shelby

Well-Known Member
Licensed User
Longtime User
You've already given me enough to sort through for the next week minimum.
 
Upvote 0

emexes

Expert
Licensed User
Well I want to bring forward the previous room (s), calculate the new room and add the two.
So what I've got pictured in my mind now is a screen with a [Clear/Reset] button, two fields for typing in the dimensions of a room, a running count and total area, an [Add] button, and a ListView of all the room dimensions you've typed in so far, eg "4000 x 3200 = 12.8 m2", "3000 x 5000 = 15 m2" etc.

When you press the [Clear/Reset] button, it zeroes the count and total area, and clears the ListView.

When you press the [Add] button, if multiplies the length and width fields and adds that area to the total (and increments the count).

(checking IsNumber(LengthEdit.Text) and IsNumber(WidthEdit.Text) first)
 
Upvote 0

emexes

Expert
Licensed User
Do you go smaller than an inch?

Or are are inch fractions decimal, eg 4.75 inches rather than 4 3/4 inches?

I'm very happy to see that yards weren't mentioned :)
 
Upvote 0

emexes

Expert
Licensed User
And what the heck do you do for say: 4'5" x 4'6" ?

Is the answer:

19.875 ft2, or
19 ft2 126 in2, or
19 7/8 ft2, or
2862 in2

???

Holy moly, I can see why this calculator might be useful.
 
Upvote 0

emexes

Expert
Licensed User
I just tried to drop the zip file onto this screen and I got a "Too Big Bro" message.
You got pictures in there?

Or try: Tools, Clean Project

to get rid of all the intermediate compilation files (which will be recreated next time you do a compilation, so: no worries about losing stuff)
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
have a look also for useful type (struct)
https://www.b4x.com/android/forum/pages/results/?query=type
example
B4X:
Dim SizeX As Float = Rooms.Get(RoomKey & "X")
Dim SizeY As Float = Rooms.Get(RoomKey & "Y")
B4X:
Type Size(x As Float,y As Float)
Dim a As Size
a.x=1
a.y=2

DoSomething(a)

Sub DoSomething(d as Size)
 ...
End Sub
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
O.K. Great,
Thanks Marcus
if you define this type/struct into a class you can add easy a functionality (with public methods like calculate, load, save, add, remove, ...).
also a good thing in b4x is u can use your own struct in a other struct.
B4X:
Type Position(x As Float,y As Float)
Type Wall(start As Position,ende As Position)
dim w as Wall
Dim walls As List
walls.Initialize
walls.Add(w)
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
have a look also for useful type (struct)

My memory's a bit hazy, but I think the reason I went with only using basic types in the map was (i) so that can use WriteMap and ReadMap, and (ii) can just open up the resultant text file and read it (or even modify it).

But for storing and transferring information within a program, you're right, I should use Types more than I do.
 
Upvote 0
Top