dim a() as integer dim i ,j as integer dim input(10) as integerfor i =0 to 10 input(i)=0 nextinput(2)=7 input(4)=7 input(8)=7 j=0 for i =0 to 10 if input(i)<>0 then redim preserve a(j) as integer a(j)=input(i) j=j+1 end if next
science 我自己写了一个,大家看看如何? Dim a As Integer Dim n, sum As Single Dim s() As Single Private Sub Command1_Click() Dim i As Integer sum = 0 For i = 1 To a sum = sum + s(i) Next i Text1.Text = Str(sum) End SubPrivate Sub Command2_Click() If Text1.Text <> "" Then n = Val(Text1.Text) a = a + 1 ReDim Preserve s(a) s(a) = n End If Text1.Text = "" End Sub
先定义一个数组: dim data() as integer '括号里不要数字 需要改变数组大小时用redim语句: redim preserve data(ubound(data())+1)'在原来的长度基础上加了1 用preserve关键字保证原来的数据不丢失。 在msdn中搜索“preserve"或者“redim"
先声明一个不含上、下标的数组: Dim A() As Long 在需要设置数组长度的时候再 ReDim 它(假设为:10,上标基于 0): ReDim A(9) 或 ReDim Preserve A(9) ' Preserve 表示保留数组中原有值
我以前这么用好像会出错。 就是: dim a() as long redim a(2) redim a(5) 这样就会出错。 redim a(2) redim a(0) 就不会。不知怎会回事。 不知现在还会不会。 我用的是VB6,SP是多少我不知道,我还没有装过。好像装过一个SP3的
dim i as integerprivate sub Command1_Click()
i=text1.text
redim aaa(i) as integer
end sub
....redim 数组名(N) as 类型,其中N就是实际输入决定,若下标从0起,个数为M,那么N就等于M-1
dim a()
b=len("abc")
redim a(b)
preserve可以保留数组的内容
dim i ,j as integer
dim input(10) as integerfor i =0 to 10
input(i)=0
nextinput(2)=7
input(4)=7
input(8)=7
j=0
for i =0 to 10
if input(i)<>0 then
redim preserve a(j) as integer
a(j)=input(i)
j=j+1
end if
next
我自己写了一个,大家看看如何?
Dim a As Integer
Dim n, sum As Single
Dim s() As Single
Private Sub Command1_Click()
Dim i As Integer
sum = 0
For i = 1 To a
sum = sum + s(i)
Next i
Text1.Text = Str(sum)
End SubPrivate Sub Command2_Click()
If Text1.Text <> "" Then
n = Val(Text1.Text)
a = a + 1
ReDim Preserve s(a)
s(a) = n
End If
Text1.Text = ""
End Sub
dim data() as integer '括号里不要数字
需要改变数组大小时用redim语句:
redim preserve data(ubound(data())+1)'在原来的长度基础上加了1
用preserve关键字保证原来的数据不丢失。
在msdn中搜索“preserve"或者“redim"
Dim A() As Long
在需要设置数组长度的时候再 ReDim 它(假设为:10,上标基于 0):
ReDim A(9)
或
ReDim Preserve A(9) ' Preserve 表示保留数组中原有值
就是:
dim a() as long
redim a(2)
redim a(5)
这样就会出错。
redim a(2)
redim a(0)
就不会。不知怎会回事。
不知现在还会不会。
我用的是VB6,SP是多少我不知道,我还没有装过。好像装过一个SP3的