|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Object reference not set to an instance of an objectHello,
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 Dim t(1000) As Integer
For i = 0 To 1000 t(i) = i Next Meelis Show quoteHide quote "Bob" <s**@sdvsd.dc> wrote in message news:%23Qq%23ApfkGHA.5036@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 > > Thanks, but if i don't know in advance how many elements there will be ...
Show quoteHide quote "Meelis" <m**@hot.ee> wrote in message news:e%23voetfkGHA.3936@TK2MSFTNGP05.phx.gbl... > Dim t(1000) As Integer > For i = 0 To 1000 > t(i) = i > Next > > > Meelis > > > > > "Bob" <s**@sdvsd.dc> wrote in message > news:%23Qq%23ApfkGHA.5036@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 > > > > > > Dim t() As Integer, i As Integer
For i = 0 To 1000 ReDim Preserve t(i) t(i) = i Next Show quoteHide quote "Bob" <s**@sdvsd.dc> wrote in message news:OKBypzfkGHA.1456@TK2MSFTNGP04.phx.gbl... > Thanks, but if i don't know in advance how many elements there will be ... > > "Meelis" <m**@hot.ee> wrote in message > news:e%23voetfkGHA.3936@TK2MSFTNGP05.phx.gbl... > > Dim t(1000) As Integer > > For i = 0 To 1000 > > t(i) = i > > Next > > > > > > Meelis > > > > > > > > > > "Bob" <s**@sdvsd.dc> wrote in message > > news:%23Qq%23ApfkGHA.5036@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 > > > > > > > > > > > > Thanks
Show quoteHide quote "Meelis" <m**@hot.ee> wrote in message news:Osw1d2fkGHA.4304@TK2MSFTNGP03.phx.gbl... > Dim t() As Integer, i As Integer > For i = 0 To 1000 > ReDim Preserve t(i) > t(i) = i > Next > > > > > "Bob" <s**@sdvsd.dc> wrote in message > news:OKBypzfkGHA.1456@TK2MSFTNGP04.phx.gbl... > > Thanks, but if i don't know in advance how many elements there will be .... > > > > "Meelis" <m**@hot.ee> wrote in message > > news:e%23voetfkGHA.3936@TK2MSFTNGP05.phx.gbl... > > > Dim t(1000) As Integer > > > For i = 0 To 1000 > > > t(i) = i > > > Next > > > > > > > > > Meelis > > > > > > > > > > > > > > > "Bob" <s**@sdvsd.dc> wrote in message > > > news:%23Qq%23ApfkGHA.5036@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 > > > > > > > > > > > > > > > > > > > > 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 ' .NET 2.x| t(i) = i | Next Dim t As List(Of Integer) | For i = 0 To 1000 The ArrayList actually holds a list of Objects, so it is not very GC | t(i) = i | Next 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 -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Bob" <s**@sdvsd.dc> wrote in message news:%23Qq%23ApfkGHA.5036@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 | |
[STRING] extract a word and text around it
Learning Programming FileSystemWatcher raises Changed Twice.... Overrides and mybase ?? Refer to an Instance of a form Newbie Question VB2005 - Sort DataGridView on Text (FormattedValue) of a ComboBox column instead of underlying value Timer1_Tick is never fired Application.ExecutablePath not recognisze by studio express 2005 appPath |
|||||||||||||||||||||||