Reusing string arrays

  • Thread starter Thread starter John Dann
  • Start date Start date
J

John Dann

I need to store a set of strings (filenames and paths in fact) in a
dynamic string array as in:

MyArray = Directory.Getfiles (etc)

This array needs module scope but is populated as above in a procedure
that will be called frequently to look at a changing folder contents.

The question is whether I need to (or it's good practice to) clear the
array each time before it's populated, ie presumably by:

Erase MyArray
MyArray = Directory.Getfiles (etc)

and since first time through the array will have been declared but not
populated, possibly what I should have is:

If Not MyArray is Nothing Then Erase MyArray
MyArray = Directory.Getfiles (etc)

Or is this a detail issue of no real consequence?

TIA
JGD
 
John Dann said:
I need to store a set of strings (filenames and paths in fact) in a
dynamic string array as in:

MyArray = Directory.Getfiles (etc)

This array needs module scope but is populated as above in a procedure
that will be called frequently to look at a changing folder contents.

The question is whether I need to (or it's good practice to) clear the
array each time before it's populated, ie presumably by:

Erase MyArray
MyArray = Directory.Getfiles (etc)

and since first time through the array will have been declared but not
populated, possibly what I should have is:

If Not MyArray is Nothing Then Erase MyArray
MyArray = Directory.Getfiles (etc)

Or is this a detail issue of no real consequence?

You don't need to clear the array. Just type 'MyArray =
Directory.GetFiles(...)'.
 
John,
MyArray = Directory.Getfiles (etc)

What you are doing with this is setting the reference from MyArray to the
reference from the Array you have created in Directory.Getfiles(ect).

It is not a copy of an array or something.

I hope this gives the idea?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top