7.對於每個迴圈
你不能通過迴圈變數更改陣列的內容,因為它是分配給每個元素的臨時內容。
Dim cars(2) 'collection of different cars
Dim trace 'track iteration details
cars(0) = "Ford"
cars(1) = "Audi"
cars(2) = "Prius"
For Each car in cars
trace = trace & car & " temporarily changed to "
car = "Jeep" 'affects car but not the cars array
trace = trace & car & vbNewLine
Next
MsgBox trace 'show what happened during the loop
Dim jeeps : jeeps = 0
For Each car in cars
If car = "Jeep" Then jeeps = jeeps +1
Next
MsgBox jeeps & " of the cars are Jeeps."