Class with an Array of Strings - newbie

  • Thread starter Thread starter bob garbados
  • Start date Start date
B

bob garbados

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.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top