PC Review


Reply
Thread Tools Rate Thread

2D array error...

 
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      17th Feb 2007
hi, im trying to create a 2D array of objects and ive done this before but i
must be forgetting something because i keep getting a null reference
exception at runtime....heres the code


Private arrTiles(7)() As Tile


Public Sub InitializeDisplay()

ReDim arrTiles(7)(7)

For i As Integer = 0 To 7

For j As Integer = 0 To 7

Dim tl As New Tile

tl.str = "red"
tl.Image = Image.FromFile("C:\Documents And
Settings\User\Desktop\Red.bmp")

''null reference error here!
arrTiles(i)(j) = tl

Next

Next

End Sub

any help would be great...

--
-iwdu15
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      17th Feb 2007
"iwdu15" <jmmgoalsteratyahoodotcom> schrieb
> hi, im trying to create a 2D array of objects and ive done this
> before but i must be forgetting something because i keep getting a
> null reference exception at runtime....heres the code
>
>
> Private arrTiles(7)() As Tile
>
> Public Sub InitializeDisplay()
>
> ReDim arrTiles(7)(7)



You specified that item 7 points to an array containing 8 items. Item 0,
Item 1, Item 2 ... Item 6 are still Nothing. You would have to write:

for i as integer=0 to 7
redim arrtiles(i)(7)
next



> For i As Integer = 0 To 7
>
> For j As Integer = 0 To 7
>
> Dim tl As New Tile
>
> tl.str = "red"
> tl.Image = Image.FromFile("C:\Documents And
> Settings\User\Desktop\Red.bmp")
>
> ''null reference error here!
> arrTiles(i)(j) = tl
>
> Next
>
> Next
>
> End Sub
>
> any help would be great...



You created an array of arrays, not a 2D array. If you wanted to create a
2D array, you would have to write:

Private arrTiles(7, 7) As Tile




Armin

 
Reply With Quote
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      19th Feb 2007
wow....howd i miss that.....thanks for pointing out my mistake
--
-iwdu15
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Microsoft Excel Programming 7 11th Jun 2011 12:01 AM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Microsoft Excel Programming 1 8th Nov 2005 04:21 AM
NETCF - Array.Sort Method (Array, IComparer) - error aprivate Microsoft VB .NET 3 10th May 2005 02:16 PM
Re: Help! Flashed Bios now I get an error that my RAID Array hasan error Tony Hwang Asus Motherboards 1 11th Jul 2003 01:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:22 PM.