vb如何为数组赋初值?能不能给一个数组中的每个值赋一个不同的初始值?
2种方法
1. 直接赋值,此法只适合和小数组
Dim myArray() as Integer ={1,2,3,4,5}
或Dim myArray(5)as integer
myArray(0)=1
myArray(1)=2
myArray(2)=3
myArray(3)=3
myArray(4)=5
myArray(5)=6
2.最常用的for next循环赋值
Dim myArray()as integer
For intCount as Integer= 0 to 5
myArray(intCount)=你要赋值的东西
Next
如果你要每个都不同那就这样:
Dim myArray()as integer
Dim FuZhi as integer
For Fuzhi as 0 to 5
For intCount as Integer= 0 to 5
myArray(intCount)=fuzhi
Next intCount
Next fuzhi
1. 直接赋值,此法只适合和小数组
Dim myArray() as Integer ={1,2,3,4,5}
或Dim myArray(5)as integer
myArray(0)=1
myArray(1)=2
myArray(2)=3
myArray(3)=3
myArray(4)=5
myArray(5)=6
2.最常用的for next循环赋值
Dim myArray()as integer
For intCount as Integer= 0 to 5
myArray(intCount)=你要赋值的东西
Next
如果你要每个都不同那就这样:
Dim myArray()as integer
Dim FuZhi as integer
For Fuzhi as 0 to 5
For intCount as Integer= 0 to 5
myArray(intCount)=fuzhi
Next intCount
Next fuzhi
温馨提示:答案为网友推荐,仅供参考
第1个回答 2009-05-20
dim i,j,t
dim a(1 to 5) as integer
randomize
for i=1 to 5
restart:t=int((100-1+1)*rnd+1))
for j=1 to UBound(a)
if a(j)=t then
goto restart
end if
a(i)=t
print a(i)
next i
这里给a数组中的每个值赋一个不同随机初始值
dim a(1 to 5) as integer
randomize
for i=1 to 5
restart:t=int((100-1+1)*rnd+1))
for j=1 to UBound(a)
if a(j)=t then
goto restart
end if
a(i)=t
print a(i)
next i
这里给a数组中的每个值赋一个不同随机初始值
第2个回答 2009-05-20
只能为数组中的逐个元素赋初值
参考:
dim a(1 to 5) as integer
a(1)=2
a(2)=4
a(3)=5
a(4)=33
a(5)=89
参考:
dim a(1 to 5) as integer
a(1)=2
a(2)=4
a(3)=5
a(4)=33
a(5)=89