Android Question Why does List.Size show 0? [SOLVED]

Tim Chapman

Active Member
Licensed User
Longtime User
Why does my TodoList.Size show 0 in the log?
See Line 64 of the code below.
The whole project is attached if you need to see it.
Thank you in advance!

My B4A Code:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Type Todo(ID As Short, Name As String, Status As Byte, Context As Byte, Category As Byte, Priority As Int, Note As String)
    Dim table1 As Table
    Dim Statuses(12,2) As String
    Dim Categories(40,2) As String
    Dim TodoList As List
    Dim HeaderRow(7) As String
    Dim Categories(40,2) As String
    Dim n As Notification = CreateNotification("Tap to Proceed.")
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Activity.AddMenuItem("Load Table", "LoadTable")
    'Activity.AddMenuItem("Save Table", "SaveTable")
    Activity.AddMenuItem("Allow Context Notification", "AllowContextNotification")
    Activity.AddMenuItem("Clear Context Notification", "ClearContextNotification")
    Activity.AddMenuItem("Exit Program", "ExitProgram")
    LoadArrays(File.DirAssets, "Todo List.xls")
    ContextCheck
End Sub

Sub LoadArrays(Dir As String, FileName As String)
    Dim row As Long
    Dim workbook1 As ReadableWorkbook
    Dim TodoSheet As ReadableSheet
    TodoList.Initialize
    workbook1.Initialize(Dir, FileName)
    TodoSheet = workbook1.GetSheet(0)
    
    'Get the header row.
    row = 0
    
    HeaderRow(0) = TodoSheet.GetCellValue(0,row)
    HeaderRow(1) = TodoSheet.GetCellValue(1,row)
    HeaderRow(2) = TodoSheet.GetCellValue(2,row)
    HeaderRow(3) = TodoSheet.GetCellValue(5,row)
    HeaderRow(4) = TodoSheet.GetCellValue(6,row)
    HeaderRow(5) = TodoSheet.GetCellValue(9,row)
    HeaderRow(6) = TodoSheet.GetCellValue(17,row)
        
    'Load the main sheet of the spreadsheet into a list of type Todo.  See here for an example under SortType: https://www.b4x.com/android/help/collections.html#list_sorttype
    'Log(TodoSheet.RowsCount)
    For row = 0 To TodoSheet.RowsCount - 1
        If IsNumber(TodoSheet.GetCellValue(2,row)) Then
            If TodoSheet.GetCellValue(2,row) > 0 And TodoSheet.GetCellValue(2,row) < 5 Then
                Dim TempTodo As Todo
                TempTodo.Initialize
                TempTodo.ID = TodoSheet.GetCellValue(0,row)
                TempTodo.Name = TodoSheet.GetCellValue(1,row)
                TempTodo.Status = TodoSheet.GetCellValue(2,row)
                TempTodo.Context = TodoSheet.GetCellValue(5,row)
                TempTodo.Category = TodoSheet.GetCellValue(6,row)
                TempTodo.Priority = TodoSheet.GetCellValue(9,row)
                TempTodo.Note = TodoSheet.GetCellValue(17,row)
                TodoList.Add(TempTodo)
                ExitFlag = 0
            End If
        Else
            ExitFlag = 1 'Found the first blank cell.
        End If
        If ExitFlag = 1 Then Exit
    Next
Log("Todo List Size = "&TodoList.Size)

For row = 1 To TodoList.Size
    Log("Todo " & row & " = " & TodoList.Get(row))
Next
End Sub
 

Attachments

  • TimTodo Works.zip
    189 KB · Views: 105

aeric

Expert
Licensed User
Longtime User
Check whether the value passes the 3 checks. Use Log to check the value.
B4X:
TodoSheet.GetCellValue(2, row)

It is better you attach the sample excel file.
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Could it be you need to change
B4X:
For row = 0 To TodoSheet.RowsCount - 1

to

B4X:
For row = 1 To TodoSheet.RowsCount - 1

So you dont read the header line again (which probably fails on your if lines)
 
Upvote 1

aeric

Expert
Licensed User
Longtime User
@Daestrum is right!
B4X:
    Log(TodoSheet.RowsCount)
    For row = 1 To TodoSheet.RowsCount - 1
        Dim value As String = TodoSheet.GetCellValue(2, row)
        'Log(row & ": " & value)
        If IsNumber(value) Then
            Dim s As Int = value
            If s > 0 And s < 5 Then
                Dim TempTodo As Todo
                TempTodo.Initialize
                TempTodo.ID = TodoSheet.GetCellValue(0, row)
                TempTodo.Name = TodoSheet.GetCellValue(1, row)
                TempTodo.Status = TodoSheet.GetCellValue(2, row)
                TempTodo.Context = TodoSheet.GetCellValue(5, row)
                TempTodo.Category = TodoSheet.GetCellValue(6, row)
                TempTodo.Priority = TodoSheet.GetCellValue(9, row)
                TempTodo.Note = TodoSheet.GetCellValue(17, row)
                TodoList.Add(TempTodo)
                ExitFlag = 0
            End If
        Else
            ExitFlag = 1 'Found the first blank cell.
        End If
        If ExitFlag = 1 Then Exit
    Next
    Log("Todo List Size = " & TodoList.Size)

    For row = 0 To TodoList.Size - 1
        Log("Todo " & (row + 1) & " = " & TodoList.Get(row).As(Todo).Name)
    Next
 
Upvote 0
Top