how do you empty an array

D

djcamo

Hi,

I have an issue trying to remove an item from an array only having one
item.

Here's the scenario.

I use this proedure to create 3 variant arrays, one for people present
at a meeting, one for apologies and one for absentees. (max of 8
items)

strPresent = GetPrivateProfileString32(Cini, "Councillors",
"Present")
strApology = GetPrivateProfileString32(Cini, "Councillors",
"Apology")
strAbsent = GetPrivateProfileString32(Cini, "Councillors",
"Absent")
varPresent = Split(strPresent, ",")
varApology = Split(strApology, ",")
varAbsent = Split(strAbsent, ",")

If some one leaves during a meeting I remove them from the 'present'
array and add them to the 'absent' array. When they come back I want
to do the opposite.

My problem is that if I erase the 'absent' array I cannot acess it
again.

I have also tried to Redim it but this does not do what I want either,
I get an empty item, not an empty array. I did read something about
using -1 to redim but this threw up an error.

Is there any way of removing the item and still having the array
available.

Hope this is enough info.

Cheers
David
 
D

Doug Robbins - Word MVP

Dim myarray As Variant
myarray = Split("one,", ",")
MsgBox myarray(0)
myarray(0) = ""
MsgBox myarray(0)
myarray(0) = "two"
MsgBox myarray(0)


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
T

Tony Jollans

Something like this, which you probably want to make into a function that
takes two arrays and a name, and to which you might want to add some error
checking:

Person = "Person Leaving"
varPresent = Split(Replace(Replace(Join(varPresent, ","), Person, ""),
",,", ","), ",")
varAbsent = Split(Join(varAbsent, ",") & "," & Person, ",")

The arrays will always be 'available' but may have no contents, no elements.
You don't say how you are using them, beyond the implicit fact that they are
somehow to be changed in real time.
 

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

Top