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 6 1445
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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl... 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
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/xml/lead"), _
System.Xml.Serialization.XmlArrayItemAttribute([Namespace]:="urn:/crmondemand/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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:Of**************@TK2MSFTNGP11.phx.gbl...
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
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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message
news:#1**************@TK2MSFTNGP15.phx.gbl... 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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:Of**************@TK2MSFTNGP11.phx.gbl...
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
Thanks that worked for initializing an array but how do I add to an alrady initialized array? That is going to be what
I need to do most. Why doesn't System.Array have an append or add method (seems like an obvious need to me)?
--Buddy
Tor Bådshaug wrote: 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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:#1**************@TK2MSFTNGP15.phx.gbl...
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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:Of**************@TK2MSFTNGP11.phx.gbl...
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
Hello Buddy,
If you need to add to an array, why not use an ArrayList type instead. It
has the methods you seek.
--- Nick
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message
news:ue**************@TK2MSFTNGP15.phx.gbl... Thanks that worked for initializing an array but how do I add to an alrady
initialized array? That is going to be what I need to do most. Why doesn't System.Array have an append or add method
(seems like an obvious need to me)?
--Buddy
Tor Bådshaug wrote: 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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:#1**************@TK2MSFTNGP15.phx.gbl...
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
justfine.
Public Class MyTestClass Public Test(4) As String End Class
Hope this helps. Tor Bådshaug tor.badshaug [//at\\] bekk.no.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:Of**************@TK2MSFTNGP11.phx.gbl...
>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
The class wasn't created by me it was auto generated by the WebServices Proxy Class wizard. I'm just trying to figure
out how to use it.
--Buddy
Nick Malik wrote: Hello Buddy,
If you need to add to an array, why not use an ArrayList type instead. It has the methods you seek.
--- Nick
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:ue**************@TK2MSFTNGP15.phx.gbl...
Thanks that worked for initializing an array but how do I add to an alrady
initialized array? That is going to be what
I need to do most. Why doesn't System.Array have an append or add method
(seems like an obvious need to me)?
--Buddy
Tor Bådshaug wrote:
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.
"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message news:#1**************@TK2MSFTNGP15.phx.gbl...
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. > >"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message >news:Of**************@TK2MSFTNGP11.phx.gbl. .. > > > >>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 > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Greg Baker |
last post by:
I don't know what standard protocol is in this newsgroup. Am I allowed to
post code and ask for help? I hope so.. :)
Here's my problem: I am trying problem 127 of the valladolid online...
|
by: Randell D. |
last post by:
Folks,
Here's my problem:
I am createing an array in a file using the reslut of some PHP and MySQL
processing. An example of my array would be
examlpe="example one";
examlpe="example...
|
by: Buddy Ackerman |
last post by:
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:
|
by: Timothy Madden |
last post by:
Hello
If I write a function like this
void Process(double Data)
{ ... }
it is ok, but if I try
class DataProcess
{
double (&Data);
DataProcess(double Data)
|
by: Peter B. Steiger |
last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C
is a simple word game that involves stringing together random lists of
words. In the Pascal version the whole array was...
|
by: baumann.Pan |
last post by:
hi all,
i want to get the address of buf, which defined as
char buf = "abcde";
so can call
strsep(address of buf, pointer to token);
|
by: ALI-R |
last post by:
Is it a possibel to assign an array to a DataColumn then bind it to a Combo
box??
Is the follwoing code right?
public static DataSet InsertParamsToDS(ReportParameter arrParams)
{
DataSet...
|
by: Brett |
last post by:
I have created a structure with five fields. I then create an array of this
type of structure and place the structure into an array element. Say index
one. I want to assign a value to field3 of...
|
by: roopa.v1 |
last post by:
Hi,
How to assign long to character array and later extract it
|
by: bharathi228 |
last post by:
hi,
how to assign a array as datasource to datagridview in vb.net.
my problem is
iam having an array with 60 values
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |