PC Review


Reply
Thread Tools Rate Thread

Array nullexception

 
 
latin & geek via DotNetMonster.com
Guest
Posts: n/a
 
      18th Apr 2007
dear all,

hi. i have a little sub routine which works fine in my dummy test program,
but when i insert it in my main program it throws errors.

this is the subroutine:

Public Sub TagListing()
'adds a tag category from the tag stack into the unique tag
collection
Try
TagStrings.Push(JustForArrayInclusion)
TagStrings.CopyTo(OldTags, moveit)
moveit = moveit + 1
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.OKOnly, errortitle)
End Try
End Sub


i get this error at the CopyTo line:

SystemArgumentNullException: Value cannot be null
Parameter name: array
at Systems.Collections.Stack.CopyTo(Array array,Int32 index)
at Catalogue.Module1.TagListing() [....] at line 137

i've declared my array like this in the same module:
'Array to hold all the unique tag categories.
'Used In: TagListing(), BtF3OldTags_Click, Form4_Load
Public OldTags As String()

moveit is correctly at zero the first time around (it's called from a FOR
loop), so i don't understand what the problem is!

can someone please help?

also, one final doubt, what's the difference between
Dim MyArray( ) as String
&
Dim MyArray as String( ) ?

thanks a lot!

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200704/1

 
Reply With Quote
 
 
 
 
=?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
Guest
Posts: n/a
 
      18th Apr 2007
latin & geek via DotNetMonster.com wrote:
> dear all,
>
> hi. i have a little sub routine which works fine in my dummy test program,
> but when i insert it in my main program it throws errors.
>
> this is the subroutine:
>
> Public Sub TagListing()
> 'adds a tag category from the tag stack into the unique tag
> collection
> Try
> TagStrings.Push(JustForArrayInclusion)
> TagStrings.CopyTo(OldTags, moveit)
> moveit = moveit + 1
> Catch ex As Exception
> MsgBox(ex.ToString, MsgBoxStyle.OKOnly, errortitle)
> End Try
> End Sub
>
>
> i get this error at the CopyTo line:
>
> SystemArgumentNullException: Value cannot be null
> Parameter name: array
> at Systems.Collections.Stack.CopyTo(Array array,Int32 index)
> at Catalogue.Module1.TagListing() [....] at line 137
>
> i've declared my array like this in the same module:
> 'Array to hold all the unique tag categories.
> 'Used In: TagListing(), BtF3OldTags_Click, Form4_Load
> Public OldTags As String()


This declares a reference to the array, but it doesn't create the array
itself. You also need to create the array:

OldTags = New String()

> moveit is correctly at zero the first time around (it's called from a FOR
> loop), so i don't understand what the problem is!
>
> can someone please help?
>
> also, one final doubt, what's the difference between
> Dim MyArray( ) as String


This is the older syntax, inherited from VB 6.

> &
> Dim MyArray as String( ) ?


This is the new syntax introduced in VS.NET. It's more consistent with
how .NET works, as an array in .NET are just another data type, and not
a special kind of variable as in VB 6.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
=?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
Guest
Posts: n/a
 
      18th Apr 2007
Göran Andersson wrote:
>> i've declared my array like this in the same module:
>> 'Array to hold all the unique tag categories. 'Used In:
>> TagListing(), BtF3OldTags_Click, Form4_Load
>> Public OldTags As String()

>
> This declares a reference to the array, but it doesn't create the array
> itself. You also need to create the array:
>
> OldTags = New String()


Oops. Of course you need to specify a size for the array:

OldTags = New String(42)

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
latin & geek via DotNetMonster.com
Guest
Posts: n/a
 
      19th Apr 2007
oh, i see! thanks... you're absolutely right, it works once i do that. thanks
a lot!

Göran Andersson wrote:
>>> i've declared my array like this in the same module:
>>> 'Array to hold all the unique tag categories. 'Used In:

>[quoted text clipped - 5 lines]
>>
>> OldTags = New String()

>
>Oops. Of course you need to specify a size for the array:
>
>OldTags = New String(42)
>


--
Message posted via http://www.dotnetmonster.com

 
Reply With Quote
 
Branco Medeiros
Guest
Posts: n/a
 
      20th Apr 2007
Göran Anderssonwrote:
<snip>
> This declares a reference to the array, but it doesn't create the array
> itself. You also need to create the array:
>
> OldTags = New String()

<snip>

The instance will be created also if you specify the upper bound of
the array. That can be -1 (yep, you read it right) to specify an empty
(but valid) array:

Dim OldTags As String(-1)

<snip>
> > Dim MyArray( ) as String

>
> This is the older syntax, inherited from VB 6.

<snip>
> > Dim MyArray as String( ) ?

>
> This is the new syntax introduced in VS.NET. It's more consistent with
> how .NET works, as an array in .NET are just another data type, and not
> a special kind of variable as in VB 6.

<snip>

Nope, they represent valid syntax both in VB 6 *and* VB.Net. There
are folks who prefer their array indicator in the variable name
(because the *variable* is the array, not the String). The syntax you
suggest was born (actually in VB 5, if I recall correctly) to allow
the declaration of functions returning arrays (which the other syntax
can't express).

The OP doesn't specify the VB.Net version being used, but it seems
VB2005 introduces the following syntax:

Dim MyArray(0 To UpperBound) As SomeType

Which is regarded more readable than Dim MyArray(UpperBound).

Just a bit o trivia thrown in...

Regards,

Branco.

 
Reply With Quote
 
latin & geek via DotNetMonster.com
Guest
Posts: n/a
 
      20th Apr 2007
wow. i didnt know this dot net business had a history and tradition thing
happening!! )

thanks a lot. the (-1) declaration may be just what i need for another part
of the code - am off to try it.

gracias.


Branco Medeiros wrote:
>Göran Anderssonwrote:


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200704/1

 
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
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
Best Way To Catch A NullException =?Utf-8?B?VGVycmFuY2U=?= Microsoft Dot NET 17 12th Jun 2007 04:20 PM
List View variable throwing NullException Miesha.James@gmail.com Microsoft VC .NET 2 29th Mar 2007 03:38 AM
meaning of : IF(Switch; Average(array A, array B); array A) =?Utf-8?B?RFhBVA==?= Microsoft Excel Worksheet Functions 1 24th Oct 2006 06:11 PM
NullException on Exit app when performing updates on the dataset kuhrty Microsoft ADO .NET 0 20th Jul 2006 08:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 PM.