Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 18th, 2004, 10:28 AM
Authorized User
 
Join Date: Jun 2003
Location: Farmington, NM, USA.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Instantiate Integer array in a stucture

Hello all,
I'm working with VB.NET 2002, 1.0 Framework. Here's my problem: I'm trying to create a STRUCTURE with an array element. The STRUCTURE looks like this:

Private Structure StructOfLabs
    Dim LabGroup As String
    Dim Hours() As Integer
End Structure

My big problem comes when I try to put stuff into the array. I can get to the LabGroup ok, but the compiler doesn't like me trying to access Hours() until I instantiate it. It tells me:
"An unhandeled exception of type 'System.NullReferenceException' occured in UpdateCalendar.exe

Additional information: Object reference not set to an instance of an object."

myLabs(0).LabGroup = ""
myLabs(0).Hours(0) = 0

I've searched & searched and I get tantalizing hints of how to go about it, but nothing materalizes. I would sure appreciate a bit of help. Thanks, all. -RK
__________________
She stood on the bridge at midnight,
Her lips were all aquiver.
She gave a cough,
Her leg fell off,
and floated down the river.
Reply With Quote
  #2 (permalink)  
Old June 18th, 2004, 11:26 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I think your problem might be that you've not dimensioned the array - i.e. you need to either do

Code:
Private Structure StructOfLabs
    Dim LabGroup As String
    Dim Hours(0) As Integer
End Structure
OR, where you are using the array, first do

Code:
Redim StructOfLabs.Hours(0)
Reply With Quote
  #3 (permalink)  
Old June 18th, 2004, 11:56 AM
Authorized User
 
Join Date: Jun 2003
Location: Farmington, NM, USA.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

VB won't let me do the first: "Arrays declared as structure members cannot be declared with an initial size." The second suggestion did work, though. I didn't even think of trying the Redim. Thanks! -RK

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 11:02 AM
Installer Context.Parameters doesn't instantiate David_0223 C# 3 January 15th, 2008 05:47 PM
Instantiate a control vbwrangler Reporting Services 0 January 3rd, 2008 04:19 PM
instantiate a form object by its name in MS Access sky2000 Access VBA 1 May 6th, 2004 03:44 AM
Could not instantiate ActiveX control because the karthey VS.NET 2002/2003 0 July 1st, 2003 05:45 PM



All times are GMT -4. The time now is 09:25 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.