VB 怎样加将两个数组合并
Dim I As Integer
m = InputBox("", "输入数组2个数")
ReDim shuzu2(1 To m)
For I = 1 To Val(m)
A = InputBox("", "请输入数字")
shuzu2(I) = A
Text2 = Text2 & shuzu2(I) & ","
Next I
数组2的输入
Dim I As Integer
N = InputBox("", "输入数组1个数")
ReDim shuzu1(1 To N)
For I = 1 To Val(N)
A = InputBox("", "请输入数字")
shuzu1(I) = A
Text1 = Text1 & shuzu1(I) & ","
Next I
将数组2合并到数组1
Private Sub Command3_Click()
ReDim shuzu1(1 To m + N) As Integer
For I = 1 To N
shuzu1(I) = shuzu1(I)
Text3 = Text3 & shuzu1(I)
Next I
For I = N + 1 To m + N
shuzu1(I) = shuzu2(I - N)
Text3 = Text3 & shuzu1(I)
Next I
End Sub
它说系统越界。。。我想我知道我错哪了
还有就是将数组的值给TEXTBOX的时候为什么不能写
text3.text=text3.text+shuzu1(i)
而要写成Text3 = Text3 & shuzu1(I)的形式
Dim shuzu2() As Integer
Dim shuzu1() As Integer
Dim HEBING() As Integer
Dim m As String
Dim N As String
Private Sub Command2_Click()
Dim I As Integer
m = InputBox("", "输入数组2个数")
ReDim shuzu2(1 To m)
For I = 1 To Val(m)
A = InputBox("", "请输入数字")
shuzu2(I) = A
Text2 = Text2 & shuzu2(I) & ","
Next I
Command3.SetFocus
End Sub
Private Sub Command3_Click()
'For I = 1 To N
'HEBING(I) = shuzu1(I)
'Text3 = Text3 & HEBING(I)
'Next I
'For I = N + 1 To m + N
'HEBING(I) = shuzu2(I - N)
'Text3 = Text3 & HEBING(I)
'Next I
'End Sub 展开
Private Sub Command1_Click()
a = Array(1, 2, 4, 7, 9, 34, 65, 73, 78, 99, 234, 1234)
b = Array(0, 23, 33, 56, 78, 98, 99, 234, 1000, 9999)
Dim c(30)
i = 0
j = 0
k = 0
While i <= UBound(a) And j <= UBound(b)
If a(i) < b(j) Then
c(k) = a(i)
i = i + 1
Else
c(k) = b(j)
j = j + 1
End If
k = k + 1
Wend
While i < UBound(a)
c(k) = a(i)
i = i + 1: k = k + 1
Wend
While j < UBound(b)
c(k) = b(j)
j = j + 1: k = k + 1
Wend
Print "原A数组:"
For i = 0 To UBound(a)
Print a(i);
Next i
Print "原B数组:"
For i = 0 To UBound(b)
Print b(i);
Next i
Print "合并后的c数组:"
For i = 0 To k
Print c(i);
If i Mod 15 = 14 Then Print
Next i
End Sub
你开始说你要把数组1,2合并到1里不是多此一举,,开始全部写到1里不就完了,
后来好了 把数组1,2 合并到另一个数组,,这个是可行的,,
越界,,,加了个全局变量就可以了,,
代码在下面,,测试可行
Dim shuzu2(), shuzu1(), m, n As Double
Private Sub Command1_Click()
n = InputBox("", "输入数组1个数")
ReDim shuzu1(1 To n)
For I = 1 To Val(n)
A = InputBox("", "请输入数字")
shuzu1(I) = A
Text2 = Text2 & shuzu1(I) & ","
Next I
'数组2的输入
m = InputBox("", "输入数组2个数")
ReDim shuzu2(1 To m)
For I = 1 To Val(m)
A = InputBox("", "请输入数字")
shuzu2(I) = A
Text1 = Text1 & shuzu2(I) & ","
Next I
End Sub
'将数组2合并到数组1
Private Sub Command3_Click()
ReDim HEBING(1 To m + n) As Integer
For I = 1 To n
HEBING(I) = shuzu1(I)
Text3 = Text3 & HEBING(I)
Next I
For I = n + 1 To m + n
HEBING(I) = shuzu2(I - n) '在这里总说下标越界。。。
Text3 = Text3 & HEBING(I)
Next I
End Sub