Android Question Weird behavior after dim and if then

Marc De Loose

Member
Licensed User
Longtime User
B4X:
Dim colorToShow As Int = ColorDefaultMenuItem
            For j=0 To 1
                If riDashDispConfig.Graphs(j).visible=False Then
                    colorToShow=colorNotActiveItem
                End If
                Log(theId & "-" & j & " colorToShow =" & colorToShow)
            Next

when visible is False the colorToShow should be ColorNotActiveItem else ColorDefaultMenuItem
but its not.

I will only work if ad the else:

B4X:
Dim colorToShow As Int = ColorDefaultMenuItem
            For j=0 To 1
                If riDashDispConfig.Graphs(j).visible=False Then
                    colorToShow=colorNotActiveItem
                Else
                    colorToShow=ColorDefaultMenuItem
                End If
                Log(theId & "-" & j & " colorToShow =" & colorToShow)
                addMenuItem1(NumberFormat(theId,3,0) & "-" & NumberFormat(j,1,0) & ": " & Main.Datas(theId).NAME,colorToShow,NumberFormat(theId,3,0) & "-" & NumberFormat(j,1,0))
            Next

I am confused! What just happened.

For reference the complete sub that I use this in:
B4X:
Sub setMenuGraphList
    MenuListView1Previous = MenuListView1Shown
    MenuListView1Shown = MenuGraphList
    
    BaseNameToAssign=""
    
    sTittle("Graphics List",colorTitle)
        
    MenuListView1.Clear
    AddMenuSpacer
    addMenuItem1("Back",ColorBackMenuItem,clickedBack)
    AddMenuSpacer
    
    Dim i As Int=1
    Do While Main.FastDataHash(i).ID > 0
        Dim theId As Int = Main.FastDataHash(i).ID
        If Main.Datas(theId).USED = True Then
            Dim riDashDispConfig As iDashDispConfig2
            riDashDispConfig.Initialize
            riDashDispConfig = Main.iDashDisp.Get(theId)
            Dim colorToShow As Int = ColorDefaultMenuItem
            For j=0 To 1
                If riDashDispConfig.Graphs(j).visible=False Then
                    colorToShow=colorNotActiveItem
                End If
                Log(theId & "-" & j & " colorToShow =" & colorToShow)
                addMenuItem1(NumberFormat(theId,3,0) & "-" & NumberFormat(j,1,0) & ": " & Main.Datas(theId).NAME,colorToShow,NumberFormat(theId,3,0) & "-" & NumberFormat(j,1,0))
            Next
        End If
        i=i+1
    Loop
    
    AddMenuSpacer
    addMenuItem1("Back",ColorBackMenuItem,clickedBack)
    AddMenuSpacer
    
End Sub
 
Top