Created
May 31, 2017 20:55
-
-
Save simply-coded/feb68898fad5b900116b479035ab7f05 to your computer and use it in GitHub Desktop.
Use lists in VBScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'create an arraylist | |
Set list = CreateObject("System.Collections.ArrayList") | |
'add values | |
list.add "mike" | |
list.add "jeremy" | |
list.add "kate" | |
list.add "alice" | |
'add a bunch of values easily via custom sub | |
addrange list, Split("ben alice mark john alice") | |
'get an item | |
MsgBox list(2) | |
MsgBox list.item(4) | |
'change an item | |
list(2) = "katelin" | |
list.item(4) = "larry" | |
'count items | |
MsgBox list.count | |
'display all values | |
MsgBox Join(list.toarray) | |
'sort list | |
list.sort | |
list.reverse | |
'add item if doesn't exist | |
If Not list.contains("garry") Then | |
list.add "garry" | |
End If | |
'find index of item | |
MsgBox list.indexof("alice",0) | |
'find second appearance of item's index | |
MsgBox list.indexof("alice",list.indexof("alice",0) + 1) | |
'insert a new item | |
list.insert 3, "miller" | |
'remove an item | |
list.remove "alice" | |
'remove item at index | |
list.removeat 5 | |
'clone the list | |
Set names = list.clone | |
'clear the list | |
list.clear | |
'Common Methods & Properties | |
' .Add "VALUE" | |
'VALUE = .Item(INDEX) | |
'LENGTH = .Count | |
'ARRAY = .ToArray | |
' .Sort | |
' .Reverse | |
'BOOLEAN = .Contains("VALUE") | |
'INDEX = .IndexOf("VALUE", START_INDEX) | |
' .Insert INDEX, "VALUE" | |
' .Remove "VALUE" | |
' .RemoveAt INDEX | |
'LIST = .Clone | |
' .Clear | |
Sub addrange(list, range) | |
For Each item In range | |
list.add item | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can I say how much I love that this was created only 7 months ago? VBS/A is not dead! If they ever kill WMI, then VB will be dead. But, today... today is not that day. VBS/A and Windows 10 for the win!
Thanks for posting.