Value for uninitialized elements of array
-
Hi: I have created two dimensional 2 x 2 array, and assigned values for 3 elements of an array only which is shown in the following code. I was bit wondering what values will be stored in the rest of the elements of array. I assumed "nothing" will be stored for them. But I got some exception handling errors. Can any help me? My Code: Dim s(2, 2) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals("") Then MessageBox.Show("Uninitialied arrray stored nothing") End If hsprasain
-
Hi: I have created two dimensional 2 x 2 array, and assigned values for 3 elements of an array only which is shown in the following code. I was bit wondering what values will be stored in the rest of the elements of array. I assumed "nothing" will be stored for them. But I got some exception handling errors. Can any help me? My Code: Dim s(2, 2) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals("") Then MessageBox.Show("Uninitialied arrray stored nothing") End If hsprasain
They will contain
Nothing
, or in C#,null
.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
They will contain
Nothing
, or in C#,null
.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hey: If they contain nothing, can you tell me why I'm getting unhandled exceptional error while running my code? Dim s(2, 3) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals(Nothing) Then MessageBox.Show("The value of x is :" + x) End If
-
Hey: If they contain nothing, can you tell me why I'm getting unhandled exceptional error while running my code? Dim s(2, 3) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals(Nothing) Then MessageBox.Show("The value of x is :" + x) End If
-
probably because of this line:
MessageBox.Show("The value of x is :" + x)
you can't add/concat x because it is nothing. just say this:MessageBox.Show("The value of x is : Nothing")
-
No. I tried what you have suggested but it showed me some exceptional handling errors. The debugger is showing an error at:
If x.Equals(Nothing) Then
-
No. I tried what you have suggested but it showed me some exceptional handling errors. The debugger is showing an error at:
If x.Equals(Nothing) Then
Because in order to execute the Equals method on X, X actually has to have a reference to an object. It doesn't, so the exception, which you haven't told us anything about, should be "Object reference not set to an instance of an object."
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Because in order to execute the Equals method on X, X actually has to have a reference to an object. It doesn't, so the exception, which you haven't told us anything about, should be "Object reference not set to an instance of an object."
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007