Hey guys,
Ive discovered something I cant get my head around. I was going through my code and looking for potential problem spots. In one spot, I found I was basically doing this code:
For each p as LinuxCompatiblePopUp in Switches
p.deleteallrows
For i as integer = 0 to Switch_IP_Dictionary.Count-1
Try
p.AddRow str(i+1)+" - "+Switch_IP_Dictionary.Value(Switch_IP_Dictionary.Key(i))
p.RowTag(p.ListCount-1) = Switch_IP_Dictionary.Value(Switch_IP_Dictionary.Key(i))
Catch
End Try
Next
// Other code
.
Next
This code is in a method that creates rows in a listbox and theres a corresponding Pop-up menu for each row.
Now, I began to think, what if Switch_IP_Dictionary might happen to be Nil. That shouldnt happen, but what if So I changed the code:
For each p as LinuxCompatiblePopUp in Switches
p.deleteallrows
If Switch_IP_Dictionary <> Nil Then
For i as integer = 0 to Switch_IP_Dictionary.Count-1
Try
p.AddRow str(i+1)+" - "+Switch_IP_Dictionary.Value(Switch_IP_Dictionary.Key(i))
p.RowTag(p.ListCount-1) = Switch_IP_Dictionary.Value(Switch_IP_Dictionary.Key(i))
Catch
End Try
Next
End IF
// Other code
Next
Now, whenever the window that uses this routine opens, the app just hard crashes. The funny thing, this method hasnt even been called when the crash occurs. I know because I put breakpoints in and the program never gets to the break point. It crashes beforehand. In fact during the initial opening of the window, the code execution NEVER gets to the If clause because the property Switches (which is an array) has no elements. Nothing in the for/next loop is executed during the opening. Its only later. So the app crashes on code that doesnt even execute!
If I comment out the If clause lines, things work perfectly.
And, if I do this:
For each p as LinuxCompatiblePopUp in Switches
p.deleteallrows
If Switch_IP_Dictionary <> Nil Then
For i as integer = 0 to Switch_IP_Dictionary.Count-1
Try
p.AddRow str(i+1)+" - "+Switch_IP_Dictionary.Value(Switch_IP_Dictionary.Key(i))
p.RowTag(p.ListCount-1) = Switch_IP_Dictionary.Value(Switch_IP_Dictionary.Key(i))
Catch
End Try
Next
Else
End IF
// Other code
Next
Things work just fine as well - no crash. It is only when I have the IF/End If in the code when checking for a NIL dictionary.
Im stumped .