Android Question Would you please test my logic?

JonnyCav

Member
As I battle on with learning this wonderful software and just like my logic critiqued, if you'd be so kind.

1. DB result set returns x number of records 'id' values assigned to .text of CLV buttons
2. If a particular button is pressed then INSERT into DB Table 1
3. Add values pertaining to that record(button) to a LISTofLists
4. Goto '2' if applicable until 'DONE' button is clicked and call a Private Sub

In Private Sub

5. For each list in the list get 'item'
6. Using 'item' , INSERT 'item' or UPDATE 'item' into DB Table 2
7. Finish

Any problem with this?
 
Solution
My testing has realised that this can't work (as far as I can see) because each SELECTED button press doesn't return the value I expected.

Back to the drawing board!

JonnyCav

Member
My testing has realised that this can't work (as far as I can see) because each SELECTED button press doesn't return the value I expected.

Back to the drawing board!
 
Upvote 0
Solution

josejad

Expert
Licensed User
Longtime User
It's easier to get help if you upload a small project with your work... maybe you have things clear in your head, but sometimes it's not easy to express it without watching some code.

For example,:

SELECTED button press doesn't return the value I expected

This is not a problem with your logic, but with the implementation of it which could probably be answered by watching your code, or opening another thread with a subject like: "CLV Button doesn't return the expected value", with your project uploaded.
 
Last edited:
Upvote 0

JonnyCav

Member
After watching Erel's video on 'Collections' for the umpteenth time and having practised and learnt, I'm being stumped by the fact a MAP will 'ONLY' overwrite an entry if the key already exists.
I am adding a key (unique id from a db) and a value (name) but the map .put is returning null when logged?


B4X:
Private Sub btnStudentsATT_Click
    Dim sname As String = btnStudentsATT.Text
    Dim groups As Map
    
    groups.Initialize

    
    Dim btnATT As Button=Sender
    
    Msgbox2Async("Add "& btnATT.Text &" to Attendance?", "Add Attendance", "Yes", "", "No", Null, False)
    Wait For Msgbox_Result (Result As Int)
    
    If Result = DialogResponse.POSITIVE Then
        lblAttendance.Enabled = False
        lblScore.Enabled = False
        lblHelp.Enabled = False
        lblAdmin.Enabled = False
        lblHome.Enabled = False
        btnBack.Enabled = False
        btnUpdateAttendance.Enabled = True
        Sid = btnATT.Tag
        
        
        Starter.sql.ExecNonQuery2("INSERT INTO attendance VALUES (?, ?, ?, ? ,?, ?, ?,null)", Array As Object(Sid, selectedGroup, btnATT.Text, AcYear, txtClassDate.Text, txtClassPeriod.Text, "P"))
        
        btnATT.TextColor=xui.Color_LightGray

Log(Sid)
Log(sname)

        groups.Put(Sid,sname)
    Else
        
    End If

Log(groups.Size)

    
End Sub

LOG (after each different button is pressed) Variables return the correct data but the map size remains at '1'

1st selected button

72
Ambe
1

2nd selected button

73
Ambe
1
 
Upvote 0

JonnyCav

Member
Sorry. Updated code


[CODE lang="b4x" title="Private Sub btnStudentsATT_Click Dim groups As Map groups.Initialize Dim btnATT As Button=Sender Msgbox2Async("Add "& btnATT.Text &" to Attendance?", "Add Attendance", "Yes", "", "No", Null, False) Wait For Msgbox_Result (Result As Int) If Result = DialogResponse.POSITIVE Then lblAttendance.Enabled = False lblScore.Enabled = False lblHelp.Enabled = False lblAdmin.Enabled = False lblHome.Enabled = False btnBack.Enabled = False btnUpdateAttendance.Enabled = True Sid = btnATT.Tag Dim sname As String = btnATT.Text groups.Put(Sid,sname) Starter.sql.ExecNonQuery2("INSERT INTO attendance VALUES (?, ?, ?, ? ,?, ?, ?,null)", Array As Object(Sid, selectedGroup, btnATT.Text, AcYear, txtClassDate.Text, txtClassPeriod.Text, "P")) btnATT.TextColor=xui.Color_Li"]Private Sub btnStudentsATT_Click

Dim groups As Map
groups.Initialize


Dim btnATT As Button=Sender

Msgbox2Async("Add "& btnATT.Text &" to Attendance?", "Add Attendance", "Yes", "", "No", Null, False)
Wait For Msgbox_Result (Result As Int)

If Result = DialogResponse.POSITIVE Then
lblAttendance.Enabled = False
lblScore.Enabled = False
lblHelp.Enabled = False
lblAdmin.Enabled = False
lblHome.Enabled = False
btnBack.Enabled = False
btnUpdateAttendance.Enabled = True
Sid = btnATT.Tag
Dim sname As String = btnATT.Text

groups.Put(Sid,sname)
Starter.sql.ExecNonQuery2("INSERT INTO attendance VALUES (?, ?, ?, ? ,?, ?, ?,null)", Array As Object(Sid, selectedGroup, btnATT.Text, AcYear, txtClassDate.Text, txtClassPeriod.Text, "P"))

btnATT.TextColor=xui.Color_LightGray

Log(Sid)
Log(sname)

Log(groups.Size)
Else

End If



End Sub[/CODE]
 
Upvote 0
Top