這是假設(shè)你知道數(shù)組的基本特征,所以讓我們考慮如何處理在VBScript中的ASP,。 在VBScript中的數(shù)組是0,這意味著數(shù)組元素的索引總是從0開始。 0指數(shù)代表的數(shù)組 中的第一個位置,1指數(shù)代表數(shù)組中的第二位,等等。 有兩種類型的VBScript數(shù)組 - 靜態(tài)和動態(tài)。靜態(tài)數(shù)組留在其整個壽命固定的大小。要 使用靜態(tài)的VBScript數(shù)組你需要知道的前期元素這個數(shù)組將包含的最大數(shù)量。如果您 需要索引的大小可變更為靈活的VBScript數(shù)組,那么你可以使用動態(tài)的VBScript數(shù)組 。 VBScript中動態(tài)數(shù)組索引的大小可以增加/在其壽命減少。 靜態(tài)數(shù)組 讓我們創(chuàng)建一個數(shù)組所謂'arrCars',將舉行5車的名字 <%@ LANGUAGE="VBSCRIPT" %> <% 'Use the Dim statement along with the array name 'to create a static VBScript array 'The number in parentheses defines the array’s upper bound Dim arrCars(4) arrCars(0)="BMW" arrCars(1)="Mercedes" arrCars(2)="Audi" arrCars(3)="Bentley" arrCars(4)="Mini" 'create a loop moving through the array 'and print out the values For i=0 to 4 response.write arrCars(i) & "<br>" Next 'move on to the next value of i %> 下面是另一種方式來定義VBScript數(shù)組: <% 'we use the VBScript Array function along with a Dim statement 'to create and populate our array Dim arrCars arrCars = Array("BMW","Mercedes","Audi","Bentley","Mini") 'each element must be separated by a comma 'again we could loop through the array and print out the values For i=0 to 4 response.write arrCars(i) & "<br>" Next %> 動態(tài)數(shù)組 動態(tài)數(shù)組派上用場當(dāng)你不知道有多少項目,您的數(shù)組將舉行。要創(chuàng)建動態(tài)數(shù)組你應(yīng)該 一起使用數(shù)組的名稱Dim語句沒有指定,上界: <% Dim arrCars arrCars = Array() %> 為了使用這個數(shù)組,你需要使用ReDim語句來定義數(shù)組的上界: <% Dim arrCars arrCars = Array() Redim arrCars(27) %> 如果將來您需要調(diào)整這個數(shù)組,你應(yīng)該使用ReDim語句了。要非常小心的ReDim語句。 當(dāng)您使用ReDim語句你失去了所有的數(shù)組元素。與使用ReDim語句一起保存的關(guān)鍵字將 保持?jǐn)?shù)組我們已經(jīng)增加了大?。?br /><% Dim arrCars arrCars = Array() Redim arrCars(27) Redim PRESERVE arrCars(52) %>