Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing an array

Status
Not open for further replies.

emblewembl

Programmer
May 16, 2002
171
0
0
GB
Hi,

I need to clear an array and am not sure how to do this. Can anyone tell me or point me in the right direction?

Thanks!

i love chocolate
 
Hi John, Thanks for your reply. I tried using myarray = Nothing to reset it but it doesn't seem to be working for me. I'll explain exactly what I'm doing so you understand what I mean.

1. BuildArray() 'populates array with item one details
2. WriteArray(1) 'writes contents to screen
3. ResetArray() 'sets array = nothing
4. WriteArray(2) 'writes array to confirm it is empty

But I get this error on the second time it tries to write the array (which should now be empty). The error is:

System.NullReferenceException: Object reference not set to an instance of an object.

How can I achieve clearing the array without this happening?



i love chocolate
 
Since the array is now "nothing" then you can not try to access the array without getting an error.

Simply check to see if it is nothing:

if myArray is nothing then
'Array has been cleared
else
'Array has not been cleard
end if


HTH!

Kevin B.
.Net Programmer [thumbsup]
 
If you MUST have an "empty" aray, then use
Redim ary(-1) ' Yes...-1 Ubound gives ary.Length=0

Dim ary() as string and Dim ary(-1) as string are not the same. The first is an object with value NOTHING while the second is an array with Length = 0 (Ubound=-1)


Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top