ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   clearing an array (https://www.excelbanter.com/excel-programming/392041-clearing-array.html)

Mark

clearing an array
 
this seems like it should be easy, but a couple of things aren't working.

if you have declared an array:

dim arParameters() as string

and then later defined it:

redim arParameters(1,2) as string

how can you clear it out? Sort of like an UNdim ? Not just redefine it to
another value, but put it back in the state it was in in the first place,
right after the

dim arParameters() as string

??

Rick Rothstein \(MVP - VB\)

clearing an array
 
this seems like it should be easy, but a couple of things aren't working.

if you have declared an array:

dim arParameters() as string

and then later defined it:

redim arParameters(1,2) as string

how can you clear it out? Sort of like an UNdim ? Not just redefine it
to
another value, but put it back in the state it was in in the first place,
right after the

dim arParameters() as string


Use the Erase statement...

Erase arParameters

You might want to look it up in the help files as it works "differently" for
dynamic as opposed to fixed arrays and what happens depends on the data type
of the array.

Rick


Mark

clearing an array
 
Thanks!

I will look it up.

'Erase' ... almost like English.

Thanks again.

"Rick Rothstein (MVP - VB)" wrote:

this seems like it should be easy, but a couple of things aren't working.

if you have declared an array:

dim arParameters() as string

and then later defined it:

redim arParameters(1,2) as string

how can you clear it out? Sort of like an UNdim ? Not just redefine it
to
another value, but put it back in the state it was in in the first place,
right after the

dim arParameters() as string


Use the Erase statement...

Erase arParameters

You might want to look it up in the help files as it works "differently" for
dynamic as opposed to fixed arrays and what happens depends on the data type
of the array.

Rick



Alan Beban

clearing an array
 
Erase arParameters

Alan Beban

mark wrote:
this seems like it should be easy, but a couple of things aren't working.

if you have declared an array:

dim arParameters() as string

and then later defined it:

redim arParameters(1,2) as string

how can you clear it out? Sort of like an UNdim ? Not just redefine it to
another value, but put it back in the state it was in in the first place,
right after the

dim arParameters() as string

??


Mark

clearing an array
 
Thanks, Rick, that worked fine.

The problem I was having was that two variables that I thought would be
totally out of scope and gone away when the code terminated, did not.

But, I've reset the one in the code now, and the Erase statement that you
suggested has taken care of that.


Mark

clearing an array
 
thanks. got it. it works for what I need.

"Alan Beban" wrote:

Erase arParameters




All times are GMT +1. The time now is 08:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com