本文介绍了如何在VBScript中声明一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel中使用了它,并且效果很好.

I used this in Excel and it works fine.

dim varScreen (0 to 2) as string
varScreen(0) = "sample 1"
varScreen(1) = "sample 2"
varScreen(2) = "sample 3"

我正在尝试将此数组转换为VBScript,但我不断收到此错误:

I am trying to translate this array to VBScript but I keep getting this error:

Line: 14
Error: Expected ')'

我尝试了各种选项,删除了as stringdim varScreen as array,但仍然出现错误.

I have tried various options, removed as string, dim varScreen as array but I still get the error.

正确的语法是什么?

推荐答案

VBScript的(变量和)数组无法键入,因此不能按原样"输入. VBscript的数组是从零开始的,所以没有(x to y)",只有(z)",其中z是数组的最后一个索引(不是大小).在代码中:

VBScript's (variables and) arrays can't be typed, so no "as Whatever". VBscript's arrays are zero-based, so no "(x To y)" but only "(z)" where z is the last index (not the size) of the array. In code:

>> Dim varScreen(2)
>> varScreen(0) = "sample 1"
>> varScreen(1) = "sample 2"
>> varScreen(2) = "sample 3"
>> WScript.Echo Join(varScreen, "|")
>>
sample 1|sample 2|sample 3
>>

这篇关于如何在VBScript中声明一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 17:35