Using the code below, why does the iif statement not set the permissionFlag to true, but the if statement does? They should be the same exact logic and I do not understand.
I have written some code below to demonstrate my issue. Copy and paste it into asp vb code behind and set the break point where noted in the comment in the code. I made this very easy to replicate.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'' create a datatable: here is what the table will
'' consist of
'' col1 col2
'' 1 1
'' 2 1
'' 3 1
'' 4 1
Dim dt As New DataTable
dt.Columns.Add("col1")
dt.Columns.Add("col2")
Dim dr As DataRow
For i As Integer = 1 To 4
dr = dt.NewRow
dr(0) = i
dr(1) = 1
dt.Rows.Add(dr)
Next
Dim permissionFlag As Boolean = False
''loop through every row in the table we just created,
''and if the 2nd column is = 0 then the permissionFlag
''will be false, else the permissionFlag will be true
For Each drow As DataRow In dt.Rows
''check the 2nd column, this is a 1 if user has the permission
''but for some reason, permissionFlag still winds up false after
''this runs.
''***************** place breakpoint here to check value of
''***************** permissionFlag after each if statement
IIf(CInt(drow(1)) = 0, permissionFlag = False, permissionFlag = True)
''this next if statement is the same logic as the above, except
''the above iif statement is not working correctly, and this one is.
''permissionFlag is scwitched to true after this statement runs
''i don't know why, they both look correct to me.
If CInt(drow(1)) = 0 Then
permissionFlag = False
Else
permissionFlag = True
End If
Next
End Sub