There are definitely other options besides the one i mentioned.
Just make sure that in one way or the other, that the variable references an
instantiated array object before it is used.
Public ListOfLead() simply declares it. Using "ListOfLead(4)" instantiates
the array object (an array with 5 elements - each element is Nothing, but
the array itself is no longer Nothing).
So, another approach to your code may be to ensure that the array is
initialized from outside the class
clsTest.Test = New String() {"First Item", "Second Item", "Third Item",
"Fourth Item", "Fifth Item"}
Analogously I would use code to add a lead to the ListOfLead-array (assuming
parameter-less constructor of the classes involved).
Dim leadInput As New LeadWS_LeadInsert_Input
leadInput.ListOfLead = New Lead1() { new Lead1 }
If you want to add a new Lead1 object to the array at the end of a current
array (if an initialized and non-empty array already exists), you will have
to add some logic to handle that. (However, there are other datastructures
that
are more appropriate for this.
Hope this helps.
Tor Bådshaug
tor.badshaug [//at\\] bekk.no.
That's a little strange because the example that I posted was based on
an
example class that was autogenerated from the
SOAP Proxy Class Wizard in WebMatrix. Here is the class:
<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:crmondemand/ws/
lead/")> _
Public Class LeadWS_LeadInsert_Input
'<remarks/>
<System.Xml.Serialization.XmlArrayAttribute([Namespace]:="urn:/crmondemand/x
ml/lead"), _
System.Xml.Serialization.XmlArrayItemAttribute([Namespace]:="urn:/crmondeman
d/xml/lead", IsNullable:=false)> _
Public ListOfLead() As Lead1
End Class
So, how would you add a lead to the ListOfLead() array?
--Buddy
Tor Bådshaug wrote:
When you get this runtime-error, there is some problem with an object
reference that is not initialized.
In your case, the problem is inside your "MyTestClass". The public
member
"Test()" defines a variable that
refers to an array of strings, but in your code, the array is never
initialized.
If you change your code to the listing below, your code should work just
fine.
Public Class MyTestClass
Public Test(4) As String
End Class
Hope this helps.
Tor Bådshaug
tor.badshaug [//at\\] bekk.no.
I created a simple class:
Public Class MyTestClass
Public Test() As String
End Class
I tried to assign some values to the array Test() and display them like
this:
Dim clsTest As New MyTestClass
Dim r As String
clsTest.Test.SetValue("First Item", 0)
clsTest.Test.SetValue("Second Item", 1)
clsTest.Test.SetValue("Third Item", 2)
clsTest.Test.SetValue("Fourth Item", 3)
clsTest.Test.SetValue("Fifth Item", 4)
For Each r in clsTest.Test
response.write(r & "<br>")
Next
I get an "Object reference not set to an instance of an object."
exception
on
the line 'clsTest.Test.SetValue("First Item", 0)'.
I don't understand why. WTF.
--Buddy