作者:手机用户2502871157 | 来源:互联网 | 2023-01-09 12:57
1> Lankymart..:
如果要逐行声明数组值以允许注释,则有两个选项.
如果您有固定数量的数组项,则可以定义该数组,然后填充每个元素.
Dim receipes(4)
Dim receipe
receipes(0) = "chicken soup" 'Chicken Soup
receipes(1) = "turkey" 'Turkey
receipes(2) = "mash potatoes" 'Mash Potatoes
receipes(3) = "yams" 'Yams
receipes(4) = "stuffing" 'Stuffing
For Each receipe In receipes
WScript.Echo receipe
Next
输出:
chicken soup
turkey
mash potatoes
yams
stuffing
如果需要动态声明,可以使用ReDim
.的Preserve
关键字告诉ReDim
调整大小的尺寸时,以不为空数组.
Dim receipe
ReDim receipes(0)
receipes(0) = "chicken soup" 'Chicken Soup
ReDim Preserve receipes(1)
receipes(1) = "turkey" 'Turkey
ReDim Preserve receipes(2)
receipes(2) = "mash potatoes" 'Mash Potatoes
ReDim Preserve receipes(3)
receipes(3) = "yams" 'Yams
ReDim Preserve receipes(4)
receipes(4) = "stuffing" 'Stuffing
For Each receipe In receipes
WScript.Echo receipe
Next
输出:
chicken soup
turkey
mash potatoes
yams
stuffing
有用的链接
使用线连续字符
声明动态数组未按预期工作
ReDim声明 - Vbscript参考