-
February 25th, 2013, 10:34 AM
#1
Insert an Item into a Collection
Hi folks
I've this trouble: I've several names grouped into an array of strings. The dimension of this array isn't fixed, because the user can add and remove an item from it. The array must be sorted, too. All these requests are difficult to carry out using an array, so, I decided to use a collection insted.
To add and remove an item there are the direct methods, but to insert a new item between two already existing? What I've to do?
I tried to use the Add method specifying the <Before> param but it raises an error. The code used is below:
Code:
Dim c As New Collection
Private Sub Command2_Click()
Dim i As Variant
For Each i In c
MsgBox i
Next i
End Sub
Private Sub Form_Load()
With c
.Add "Giovanni"
.Add "Marco"
.Add "Valeria"
End With
End Sub
Private Sub Command1_Click()
Dim i As Variant
Dim s As String
s = InputBox("Inserisci 1 nome")
For Each i In c
If Asc(i) > Asc(s) Then
c.Add s, , i 'Here the error raises.
End If
Next i
End Sub
If I was not clear enough, please tell me. Thanks to anyone who tries to help me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|