By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,838 Members | 1,693 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,838 IT Pros & Developers. It's quick & easy.

Object reference not set to an instance of an object

P: n/a
Bob
Hello,

I'm starting with vb.net and i get this error:
Object reference not set to an instance of an object

Dim t() As Integer
For i = 0 To 1000
t(i) = i
Next

Thanks
Bob
Jun 17 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Dim t(1000) As Integer
For i = 0 To 1000
t(i) = i
Next
Meelis


"Bob" <sd*@sdvsd.dc> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
Hello,

I'm starting with vb.net and i get this error:
Object reference not set to an instance of an object

Dim t() As Integer
For i = 0 To 1000
t(i) = i
Next

Thanks
Bob

Jun 17 '06 #2

P: n/a
Bob
Thanks, but if i don't know in advance how many elements there will be ...

"Meelis" <me*@hot.ee> wrote in message
news:e%****************@TK2MSFTNGP05.phx.gbl...
Dim t(1000) As Integer
For i = 0 To 1000
t(i) = i
Next
Meelis


"Bob" <sd*@sdvsd.dc> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
Hello,

I'm starting with vb.net and i get this error:
Object reference not set to an instance of an object

Dim t() As Integer
For i = 0 To 1000
t(i) = i
Next

Thanks
Bob


Jun 17 '06 #3

P: n/a
Dim t() As Integer, i As Integer
For i = 0 To 1000
ReDim Preserve t(i)
t(i) = i
Next


"Bob" <sd*@sdvsd.dc> wrote in message
news:OK**************@TK2MSFTNGP04.phx.gbl...
Thanks, but if i don't know in advance how many elements there will be ...

"Meelis" <me*@hot.ee> wrote in message
news:e%****************@TK2MSFTNGP05.phx.gbl...
Dim t(1000) As Integer
For i = 0 To 1000
t(i) = i
Next
Meelis


"Bob" <sd*@sdvsd.dc> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
Hello,

I'm starting with vb.net and i get this error:
Object reference not set to an instance of an object

Dim t() As Integer
For i = 0 To 1000
t(i) = i
Next

Thanks
Bob



Jun 17 '06 #4

P: n/a
Bob
Thanks

"Meelis" <me*@hot.ee> wrote in message
news:Os**************@TK2MSFTNGP03.phx.gbl...
Dim t() As Integer, i As Integer
For i = 0 To 1000
ReDim Preserve t(i)
t(i) = i
Next


"Bob" <sd*@sdvsd.dc> wrote in message
news:OK**************@TK2MSFTNGP04.phx.gbl...
Thanks, but if i don't know in advance how many elements there will be ....
"Meelis" <me*@hot.ee> wrote in message
news:e%****************@TK2MSFTNGP05.phx.gbl...
Dim t(1000) As Integer
For i = 0 To 1000
t(i) = i
Next
Meelis


"Bob" <sd*@sdvsd.dc> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
> Hello,
>
> I'm starting with vb.net and i get this error:
> Object reference not set to an instance of an object
>
> Dim t() As Integer
> For i = 0 To 1000
> t(i) = i
> Next
>
> Thanks
> Bob
>
>



Jun 17 '06 #5

P: n/a
Bob,
In addition Meelis' sample.

Consider using an ArrayList (.NET 1.x) or List(Of T) (.NET 2.0) instead.

Both are array like structures that dynamic grow "intelligently". They both
allocate a larger then needed buffer & only reallocate when the buffer in
full. Which is significantly more GC friendly then resizing the array on
each iteration of the loop.

' .NET 1.x
Dim t As ArrayList
| For i = 0 To 1000
| t(i) = i
| Next

' .NET 2.x
Dim t As List(Of Integer)
| For i = 0 To 1000
| t(i) = i
| Next

The ArrayList actually holds a list of Objects, so it is not very GC
friendly, nor type safe friendly, plus it has overridable methods which can
be a minor performance issue.

The List(Of Integer) holds a list of Integers, so it is very GC friendly,
fully type safe, plus avoids overriable methods eliminating that possible
performance issue...

FWIW: List(Of T) is a generic class, it is a strongly typed list of what
ever type you give for T. For example:

List(Of Integer) = a strongly typed list of integers
List(Of Double) = a strongly typed list of doubles
List(Of Customer) = a strongly typed list of Customer objects
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Bob" <sd*@sdvsd.dc> wrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
| Hello,
|
| I'm starting with vb.net and i get this error:
| Object reference not set to an instance of an object
|
| Dim t() As Integer
| For i = 0 To 1000
| t(i) = i
| Next
|
| Thanks
| Bob
|
|
Jun 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.