T
Tim Anderson
Is this expected behavior?
Winform with button and listbox:
Dim i As Integer
For i = 0 To 50
Dim s As String
If i = 1 Then
s = "Only once?"
End If
Me.ListBox1.Items.Add("Test " & s)
Next
If I run this code I find that the value of s remains at
"Only once?" through all the iterations after i=1, although
it is not declared as static.
This is certainly what (might) happen in C with an
uninitialized variable, but I though VB was super-safe and
would automatically initialize variables to a sensible default?
If not, surely the VB compiler should do what the C#
compiler does and check for uninitialized variables?
Tim
Winform with button and listbox:
Dim i As Integer
For i = 0 To 50
Dim s As String
If i = 1 Then
s = "Only once?"
End If
Me.ListBox1.Items.Add("Test " & s)
Next
If I run this code I find that the value of s remains at
"Only once?" through all the iterations after i=1, although
it is not declared as static.
This is certainly what (might) happen in C with an
uninitialized variable, but I though VB was super-safe and
would automatically initialize variables to a sensible default?
If not, surely the VB compiler should do what the C#
compiler does and check for uninitialized variables?
Tim