Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Example()
- Dim students As New Collection
- students.Add ("Peter")
- students.Add ("Samantha")
- students.Remove (2)
- Debug.Print students(1)
- End Sub
- =============================================
- Sub Example()
- Dim students As New Collection
- students.Add ("Peter")
- students.Add ("Samantha")
- Dim count As Integer
- count = students.count
- For i = 1 To count
- If students(i) = "Samantha" Then
- Debug.Print i
- End If
- Next
- End Sub
- =============================================
- Sub Example()
- Dim students As New Collection
- students.Add ("Peter")
- students.Add ("Samantha")
- For Each s In students
- Debug.Print s
- Next
- End Sub
- =============================================
- Sub Example()
- Dim numbers(0 To 5) As Integer
- For i = 0 To UBound(numbers)
- numbers(i) = i + 10
- Next
- End Sub
- =============================================
- Sub Example()
- Dim numbers As Variant
- numbers = Array(10, 20, 30, 40)
- End Sub
- =============================================
- Sub Example()
- Dim numbers As Variant
- numbers = Array(10, 20, 30, 40)
- count = UBound(numbers)
- ReDim numArr(0 To count + 1) As Integer
- End Sub
- =============================================
- Sub Example()
- Dim days As Variant
- days = Array( _
- "Monday", _
- "Tuesday", _
- "Wednesday", _
- "Thursday", _
- "Friday", _
- "Saturday", _
- "Sunday")
- End Sub
- ==============================================
- Sub Example()
- Dim lastRow, row As Integer
- lastRow = Cells(Rows.Count, 2).End(xlUp).row
- ReDim arr(0 To lastRow - 1)
- For row = 1 To lastRow
- arr(row - 1) = Cells(row, 2)
- Next
- End Sub
- ==============================================
- Sub Example()
- Dim values As String
- values = Range("A1")
- items = Split(values, " ")
- For i = 0 To UBound(items)
- Debug.Print items(i)
- Next
- End Sub
- ==============================================
- Sub Example()
- Dim arrFromRange, el As Variant
- arrFromRange = Range("C1:C6")
- For Each el In arrFromRange
- Debug.Print el
- Next
- End Sub
- ==============================================
- mscorlib.dll
- ==============================================
- Dim names As New ArrayList
- names.Add("Peter")
- names.Add("Maria")
- For Each name in names
- Debug.Print name
- Next
- Debug.Print Join(names.toArray, ", ")
- ==============================================
- Sub Example()
- Dim nums As Variant
- nums = Array(10, 20, 30)
- For i = UBound(nums) To 0 Step -1
- Debug.Print nums(i)
- Next
- End Sub
- ==============================================
- Sub Example()
- Dim arrOne As Variant
- arrOne = Array(10, 20, 30)
- Dim arrTwo As Variant
- arrTwo = Array(10, 5, 30)
- Dim count As Integer
- count = UBound(arrTwo)
- Dim isIdentical As Boolean
- For i = 0 To count
- If arrOne(i) <> arrTwo(i) Then
- isIdentical = False
- Exit For
- Else
- isIdentical = True
- End If
- Next
- If isIdentical Then
- Debug.Print "Yes"
- Else
- Debug.Print "No"
- End If
- End Sub
- ==============================================
- Sub Example()
- Dim fruits As New Scripting.Dictionary
- ' Add to fruit to Dictionary
- fruits.Add key:="Apple", Item:=2.2
- fruits.Add key:="Peach", Item:=1.4
- fruits.Add key:="Plum", Item:=3.2
- 'Debug.Print fruits("Apple")
- Dim key As Variant
- For Each key In fruits.Keys
- Debug.Print key, fruits(key)
- Next key
- End Sub
- ==============================================
- Sub Example()
- Dim values As String
- values = "8 2.5 2.5 8 2.5"
- Dim arrList As Variant
- arrList = Split(values, " ")
- Dim dict As New Scripting.Dictionary
- For Each num In arrList
- If dict.Exists(num) Then
- dict(num) = dict(num) + 1
- Else
- dict.Add key:=num, Item:=1
- 'dict(num) = 1
- End If
- Next
- Dim key As Variant
- For Each key In dict.Keys
- Debug.Print key, dict(key)
- Next key
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement