Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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.
  #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)
  #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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Installer Context.Parameters doesn't instantiate David_0223 C# 3 January 15th, 2008 06:47 PM
Instantiate a control vbwrangler Reporting Services 0 January 3rd, 2008 05: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.