VB 怎样加将两个数组合并

数组1的输入DimIAsIntegerm=InputBox("","输入数组2个数")ReDimshuzu2(1Tom)ForI=1ToVal(m)A=InputBox(... 数组1的输入
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
展开
 我来答
听不清啊
高粉答主

推荐于2017-10-04 · 说的都是干货,快来关注
知道顶级答主
回答量:7.8万
采纳率:89%
帮助的人:1.9亿
展开全部

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

  Print "原B数组:"

  For i = 0 To UBound(b)

    Print b(i);

  Next i

  Print

  Print "合并后的c数组:"

  For i = 0 To k

    Print c(i);

    If i Mod 15 = 14 Then Print

  Next i

  Print

End Sub

aa4681464
2009-11-10 · TA获得超过1138个赞
知道小有建树答主
回答量:922
采纳率:0%
帮助的人:833万
展开全部
你的问题 首先没有定义全局变量,

你开始说你要把数组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
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式