Class with an Array of Strings - newbie

Class with an Array of Strings - newbie

Post by bob garbad » Fri, 15 Oct 2004 02:43:05


How would I go about filling this class with name/value pairs?

Public Class IGSParameter
Public Name() As String
Public Value() As String
End Class

I thought it would be done by the following code:
Dim igsInput as IgsParameter
igsInput = new IgsParameter
igsInput.Name(0) = "name"
igsInput.Value(0) = "value"

But it generates the error Object reference not set to an instance of an
object.
 
 
 

Class with an Array of Strings - newbie

Post by Shiv » Fri, 15 Oct 2004 03:13:48

You have allocate the array before using it:

Public Class IGSParameter
Public Name(10) As String '11 Elements
Public Value(10) As String '11 Elements
End Class

Then instantiate and use the class.

OR

After instantiation,

igsInput.Name = Array.CreateInstance (GetType (String), 10) '10 Elements
igsInput.Value = Array.CreateInstance (GetType (String), 10) '10 Elements

HTH



How would I go about filling this class with name/value pairs?

Public Class IGSParameter
Public Name() As String
Public Value() As String
End Class

I thought it would be done by the following code:
Dim igsInput as IgsParameter
igsInput = new IgsParameter
igsInput.Name(0) = "name"
igsInput.Value(0) = "value"

But it generates the error Object reference not set to an instance of an
object.