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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to manipulate elements of an array

Status
Not open for further replies.

tomzhu

IS-IT--Management
Oct 1, 2002
2
CA
Hi:

I just wonder whether there are any built-in functions/methods to delete/remove/kill or add/insert/put elements of an array. So far, what i can do is only using assignment methods to fulfil those tasks.

Thanks a lot,

Tom
 
If you treat the array as a collection you can get much more functionality. Unfortunately, I know that cos I saw a piece of code at work, never used it, so that is as much as I can remember.
But it gives you a direction to go in until someone comes up with something better.
 
This is the code example, as is.


Const Words As String = "Your,Words,In,Here"

Private mCol As Collection

Private Sub Command1_Click()

Dim strWord As String
strWord = mCol.Item(Int(Rnd * mCol.Count) + 1)
MsgBox strWord
mCol.Remove strWord
MsgBox "Now only " & mCol.Count & " words in collection"
End Sub

Private Sub Form_Load()
Dim lngIndex As Long
Dim strWoof() As String

strWoof = Split(Words, ",")
Set mCol = New Collection
For lngIndex = 0 To UBound(strWoof)
mCol.Add strWoof(lngIndex), strWoof(lngIndex)
Next lngIndex
MsgBox mCol.Count & " words in collection"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top