473,608 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array problem with custom class

I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(B yVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.n ame = name

NavButtonInfo.t ext = text

NavButtonInfo.U RL = URL

NavButtonInfo.p arentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).S etButtonInfo("h omeindex", "Life With Nate", "/index.aspx",
Nothing)
When I build and run my application, I recieve an error that tells me the
following:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]

I think I must be doing something wrong or forgetting something when I add
data to the array, but I am not sure what. Can anyone tell me what I am
forgetting? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
3 1358
you are declaring the array but never instantiating instances of it..

dim ButtonList(10) as NavButtonInfo

ButtonList(0) = new NavButtonInfo
ButtonList(0).S etButtonInfo(.. .)

seems though like SetButtonInfo should be your custructor instead so that
you can do:

ButtonList(0) = new NavButtonInfo(" homeindex", "Life With Nate",
"/index.aspx", Nothing)

If you don't know the size of the Array consider using an ArrayList.
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:OV******** *******@TK2MSFT NGP10.phx.gbl.. .
I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(B yVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.n ame = name

NavButtonInfo.t ext = text

NavButtonInfo.U RL = URL

NavButtonInfo.p arentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).S etButtonInfo("h omeindex", "Life With Nate", "/index.aspx",
Nothing)
When I build and run my application, I recieve an error that tells me the
following:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]

I think I must be doing something wrong or forgetting something when I add
data to the array, but I am not sure what. Can anyone tell me what I am
forgetting? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

Nov 19 '05 #2
Thanks. And you are right, I probably should make SetButtonInfo my
constructor. The reason I didn't do that is because I don't know how (I was
never really taught how to make constructors in VB.NET). If you could give
me a simple example, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OM******** *****@TK2MSFTNG P12.phx.gbl...
you are declaring the array but never instantiating instances of it..

dim ButtonList(10) as NavButtonInfo

ButtonList(0) = new NavButtonInfo
ButtonList(0).S etButtonInfo(.. .)

seems though like SetButtonInfo should be your custructor instead so that
you can do:

ButtonList(0) = new NavButtonInfo(" homeindex", "Life With Nate",
"/index.aspx", Nothing)

If you don't know the size of the Array consider using an ArrayList.
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:OV******** *******@TK2MSFT NGP10.phx.gbl.. .
I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(B yVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.n ame = name

NavButtonInfo.t ext = text

NavButtonInfo.U RL = URL

NavButtonInfo.p arentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).S etButtonInfo("h omeindex", "Life With Nate", "/index.aspx",
Nothing)
When I build and run my application, I recieve an error that tells me the
following:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]

I think I must be doing something wrong or forgetting something when I
add data to the array, but I am not sure what. Can anyone tell me what I
am forgetting? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/


Nov 19 '05 #3
Public Sub New(ByVal name As String, ByVal text As tring, ByVal URL As
String, ByVal parentname As String)
me.name = name
me.text = text
me.URL = URL
me.parentname = parentname
End Sub

I just realized your SetButtonInfo was shared, as are your public fields.
This would imply that you can ever have 1 value in them at a time...yet you
want to declare an array of them. My guess is that you don't mean for them
to be shared...but fell into the trap of making them shared one of at a time
to get it quasi-working. This is what your class should look like (unless I
misunderstand the context, which is highly likely):

Do note that changing from shared to not is a pretty big change, so you
should learn the difference between the two before blindly accepting what
I'm saying..both are legitimate, depending on what you are doing
(http://www.vbip.com/books/1861004915...er_4915_08.asp
http://www.ondotnet.com/pub/a/dotnet...rovbnetoo.html Google)

Public Class NavButtonInfo
private _name as string
private _text as string
private _url as string
private _parentName as string

public property Name As String
get
return _name
end get
set (value as string)
_name = value
end set
end property
public property Text As String
get
return _text
end get
set (value as string)
_name = value
end set
end property
public property Url As String
get
return _url
end get
set (value as string)
_url = value
end set
end property
public property ParentName As String
get
return _parentName
end get
set (value as string)
_parentName = value
end set
end property

Public Sub New(ByVal name As String, ByVal text As tring, ByVal URL As
String, ByVal parentname As String)
_name = name
_text = text
_URL = URL
_parentname = parentname
End Sub

End Class
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:Oh******** *****@tk2msftng p13.phx.gbl...
Thanks. And you are right, I probably should make SetButtonInfo my
constructor. The reason I didn't do that is because I don't know how (I
was never really taught how to make constructors in VB.NET). If you could
give me a simple example, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OM******** *****@TK2MSFTNG P12.phx.gbl...
you are declaring the array but never instantiating instances of it..

dim ButtonList(10) as NavButtonInfo

ButtonList(0) = new NavButtonInfo
ButtonList(0).S etButtonInfo(.. .)

seems though like SetButtonInfo should be your custructor instead so that
you can do:

ButtonList(0) = new NavButtonInfo(" homeindex", "Life With Nate",
"/index.aspx", Nothing)

If you don't know the size of the Array consider using an ArrayList.
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:OV******** *******@TK2MSFT NGP10.phx.gbl.. .
I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(B yVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.n ame = name

NavButtonInfo.t ext = text

NavButtonInfo.U RL = URL

NavButtonInfo.p arentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).S etButtonInfo("h omeindex", "Life With Nate",
"/index.aspx", Nothing)
When I build and run my application, I recieve an error that tells me
the following:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]

I think I must be doing something wrong or forgetting something when I
add data to the array, but I am not sure what. Can anyone tell me what I
am forgetting? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3254
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) CType(local4, Short) = CType(src, Short)
1
3725
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client that accesses a Axis provided web service. The client uses the code generated, using wsdl.exe, from the wsdl file provided by the web service provider. The web response has the following schema (roughly):
7
4740
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service project. The same class lib is included in the ASP.NET Web Application that calls the web-method I can successfully call the web-method with
18
3236
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point storage and dynamically resize it when there is a new point or should I use ArrayList? Is speed noticable between the two? Regards,
9
4091
by: mupe | last post by:
Hi, i have a problem with a Type Library, which is written in C++. I am developing an application in C#.NET and have to use functions from this COM-Type Library. When I use these functions in the "old" VB it works but not in .NET. I think it is a problem with marshalling but I could not find a solution yet. First I included the Type Library in VS.NET 2003. Other functions of the TL work so the reference to the Lib must be correct.
17
7232
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
6
3858
by: djm | last post by:
hi, lets say ive this struct array in my header file public: IndepHTable(); private: struct { string word; List defList;
9
2676
by: =?Utf-8?B?RGFya21hbg==?= | last post by:
Hi, I am wondering how you multi-dimension an array function? My declared function looks like this: Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long, ByVal Val3 As String) As String() Previously I dimensioned a single dimension Array to the size I wanted and
9
2361
by: devloop | last post by:
Hi, I am a JAVA developer who just started with php5 (on a WAMPP with php5.2.1). I´ve the following problem with a little class (I wanted to put objects into the array later but even with simple strings it doesn´t work!!!!!!!!!). The output doesn´t show any letters/strings when I call the method toHtml().
2
3745
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
0
8011
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8488
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8358
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6826
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3972
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1339
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.