这样声明数组为什么有错
我用下面的方法声明数组为什么有错呢?1)
Dim arytem(6)
arytem=Array ("aa","bb","cc","dd","ee","ff","gg")
2)
Dim arytem(6) as string
arytem=Array ("aa","bb","cc","dd","ee","ff","gg")
用这种方法怎么会有错呢?我实在找不出原因....请大家帮我看看 Dim arytem(6) as string = {"aa","bb","cc","dd","ee","ff","gg"} Dim arytem
arytem = array("aa","bb","cc","dd","ee","ff","gg")
WScript.Echo arytem(0) 什么语言的数组声明? VBS 噢是外行一个,知道java数组 原帖由 shanxi 于 2009-9-29 18:54 发表 http://bbs.51testing.com/images/common/back.gif
Dim arytem(6) as string = {"aa","bb","cc","dd","ee","ff","gg"}
这样写也还是有错啊?? 原帖由 cocochen0597 于 2009-9-29 18:39 发表 http://bbs.51testing.com/images/common/back.gif
我用下面的方法声明数组为什么有错呢?
1)
Dim arytem(6)
arytem=Array ("aa","bb","cc","dd","ee","ff","gg")
2)
Dim arytem(6) as string
arytem=Array ("aa","bb","cc","dd","ee","ff","gg")
用这 ...
我想知道这样写为什么有错呢?难道声明数组提前申请一下空间是错的,声明数组不需要也不可以提前申请空间?
我试过以下这种方法是没错的..
Dim arytem
arytem = array ("aa","bb","cc","dd","ee","ff","gg") 哦 错了啊
自己看msdn:
http://msdn.microsoft.com/en-us/library/t7zd6etz(VS.85).aspx
You assign data to each of the elements of the array using an index into the array. Beginning at zero and ending at 10, data can be assigned to the elements of an array as follows: 我的理解,不晓得对不对。
dim arr(6),这个是静态的,就是定死了,就是一个存放6个参数的数组。
所以在初始化的时候,可以
arr(0)=""
arr(1)=""
....
而arr=array("1","2","3"),是返回一个动态的数组,可以是0元素的,可以是7个元素的,
所以先dimarr,这时arr不晓得是什么类型的,一个通用的参数,
然后arr=Array(),这时根据Arrray里的参数个数,来确定arr是什么东西。
arr(6)=Array("1"),一边是静态的数组,一边是动态的数组,所以提示类型不对。 纠正下,arr(6)是存放7个元素的,包含arr(0)和arr(6) 1 在vbs里只有一种数据类型:Variant
所以
Dim arytem(6) as string
arytem=Array ("aa","bb","cc","dd","ee","ff","gg")
这种写法肯定是错的
2 vbs里的array函数返回的是一个Variant
如果你这么写
Dim arytem(6)
arytem=Array ("aa","bb","cc","dd","ee","ff","gg")
就会造成array函数的返回结果类型不匹配,所以会出错
页:
[1]