I have workable code to calculate the square footage of a wall, save that result, repeat for more walls and add the areas of the previous walls to the lastly calculated wall and display a running total of all wall areas. Now I have a problem: some walls have different heights so I have to find the average of those two heights to use for calculating the newest wall. After some reading, I think I will have to use a resumable sub like a previous tutorial of Erel's e.g.
https://www.b4x.com/android/forum/t...hat-return-values-resumablesub.82670/#content
Here is my code with an attempt to start with the resumable sub between the rows of dotted lines.
My most immediate questions are: 1) Is the resumable sub what I need for calculating and then returning to the original main module?
2) Do I need an additional module for the calculating of the average height for my original area calculation?
3) Do I need another designer (.bal file) for the calculation of the average height?
I have a floor area app published and this wall area app is my next attempt at app building.
Thanks
Here is my full app (before the resumable sub code) file attached
https://www.b4x.com/android/forum/t...hat-return-values-resumablesub.82670/#content
Here is my code with an attempt to start with the resumable sub between the rows of dotted lines.
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules. Public by default.SSS
Public TotalArea As Double
Type Walls(Width As Double, Height As Double, Area As Double)
Public lstWalls As List
Public WallIndex = 1 As Int
End Sub
Sub Globals
'Variables always Private in this sub SSS
Private lblWall, lblFind, lblArea, lblTotalArea, lblWallNumber As Label
Private edtHeight, edtWidth As EditText
Private btnCalc As Button
'Private pnlBitmap As Panel
Private ltvWalls As ListView
End Sub
'---------------------------------------------------
'SS New attempt to find average of different wall heights
Sub Button1_Click
Wait For(Sum(1, 2)) Complete (Result As Int)
'I also want to divide that sum by 2 (how is that written?)
Log("result: " & Result)
Log("after sum")
End Sub
Sub Sum(a As Int, b As Int) As ResumableSub
Sleep(100)
Log(a + b)
Return a + b 'Also divide by 2
End Sub
'SS End new attempt....
'-----------------------------------------------------
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Wall1_2")
lstWalls.Initialize
ltvWalls.SingleLineLayout.Label.TextSize = 18
ltvWalls.SingleLineLayout.ItemHeight = 30dip
NewWall
' 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
Log($"Today's Date $date{DateTime.Now}"$)
'Above is smart string (using $ symbols)
'Not smart
Log("Also today is " & DateUtils.GetDayOfWeekName(DateTime.Now))
'***
'Below is smart string time
Log ($"The Time $Time{DateTime.Now}"$)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub NewWall
Private Wall As Walls
Wall.Area = 0
Wall.Height = 0
Wall.Width = 0
lstWalls.Add(Wall)
ltvWalls.AddSingleLine("Wall #" & WallIndex & " W = " & Wall.Width & " H = " & Wall.Height& " Area = " & NumberFormat(Wall.Area, 1, 2))
WallIndex = lstWalls.Size
lblArea.text = " Will Display Here"
End Sub
Sub btnCalc_Click
Private Wall As Walls
Wall.Width = edtWidth.Text
Wall.Height = edtHeight.Text
Wall.Area = Wall.Width * Wall.Height
TotalArea = TotalArea + Wall.Area
lblArea.Text = NumberFormat(Wall.Area, 1, 0) & " Square Feet"
lstWalls.Set(WallIndex - 1, Wall)
UpdateWallList
CalculateTotalArea
lblTotalArea.Text = NumberFormat(TotalArea, 1, 2) & " s.f."
End Sub
Private Sub btnNewWall_Click
NewWall
UpdateNewWallScreen
UpdateWallList
End Sub
Sub ltvWalls_ItemClick (Position As Int, Value As Object)
WallIndex = Position + 1
UpdateWallScreen
End Sub
Private Sub UpdateWallScreen
Private Wall As Walls
Wall = lstWalls.Get(WallIndex - 1)
lblWallNumber.Text = WallIndex
If Wall.Width = 0 Then
edtWidth.Text = ""
Else
edtWidth.Text = Wall.Width
End If
If Wall.Height = 0 Then
edtHeight.Text = ""
Else
edtHeight.Text = Wall.Height
End If
lblArea.Text = NumberFormat(Wall.Area, 1, 0) & " Square Feet"
lblTotalArea.Text = NumberFormat(TotalArea, 1, 2)
End Sub
Private Sub UpdateNewWallScreen
lblWallNumber.Text = WallIndex
edtWidth.Text = ""
edtHeight.Text = ""
End Sub
Private Sub UpdateWallList
Private i As Int
ltvWalls.Clear
For i = 0 To lstWalls.Size - 1
Private Wall As Walls
Wall = lstWalls.Get(i)
ltvWalls.AddSingleLine("Wall #" & (i + 1) & " W = " & Wall.Width & " H = " & Wall.Height & " Area = " & NumberFormat(Wall.Area, 1, 2))
Next
End Sub
Private Sub CalculateTotalArea
Private i As Int
TotalArea = 0
For i = 0 To lstWalls.Size - 1
Private Wall As Walls
Wall = lstWalls.Get(i)
TotalArea = TotalArea + Wall.Area
Log (TotalArea)
Next
End Sub
My most immediate questions are: 1) Is the resumable sub what I need for calculating and then returning to the original main module?
2) Do I need an additional module for the calculating of the average height for my original area calculation?
3) Do I need another designer (.bal file) for the calculation of the average height?
I have a floor area app published and this wall area app is my next attempt at app building.
Thanks
Here is my full app (before the resumable sub code) file attached
Attachments
Last edited: