vb.net数组合并 vbnet 数组

vb如何合并两个一维数组?

合并数组没有简单办法,只能一维一维的取出来,放到一新数组中。新数组维数是原两数组维数相加。

成都网站制作、网站设计中从网站色彩、结构布局、栏目设置、关键词群组等细微处着手,突出企业的产品/服务/品牌,帮助企业锁定精准用户,提高在线咨询和转化,使成都网站营销成为有效果、有回报的无锡营销推广。成都创新互联公司专业成都网站建设十年了,客户满意度97.8%,欢迎成都创新互联客户联系。

比如两个数组 A ,B

dim newAr() '如果两个数组类型相同话 ,可以定义类型。

redim newAr(ubound(A)-lbound(A)+1+ubound(B)-lbound(B)+1-1) ‘由于数组定义只能用常数表达式定义维数,所以用动态数组。

把两数组项目添加到newAr 中

dim Index as integer

dim i as integer

for i=LBound(A) to UBound(A)

newAr(Index)=A(i)

Index=Index+1

next

for i=LBound(B) to UBound(B)

newAr(Index)=B(i)

Index=Index+1

next

VB 怎样加将两个数组合并

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

VB怎么把两个数组合并

1. VB 怎样加将两个数组合并

你的问题 首先没有定义全局变量,

你开始说你要把数组1,2合并到1里不是多此一举,,开始全部写到1里不就完了,

后来好了 把数组1,2 合并到另一个数组,,这个是可行的,,

越界,,,加了个全局变量就可以了,,

代码在下面,,测试可行

Dim shuzu2(), shuzu1(), m, n As Double

Private Sub mand1_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 mand3_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

2. VB 怎样加将两个数组合并

Private Sub mand1_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数组e79fa5e98193e58685e5aeb931333337623437:" 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 。

3. 怎样把两个数组合并为一个

Private Sub mand1_Click()

Dim a(1 To 10), b(1 To 10), c(1 To 20)

Randomize

For i = 1 To 10

a(i) = Int(Rnd * 100)

b(i) = Int(Rnd * 100)

Next i

For i = 1 To 9

For j = 10 To i + 1 Step -1

If a(i) a(j) Then d = a(i): a(i) = a(j): a(j) = d

If b(i) b(j) Then d = b(i): b(i) = b(j): b(j) = d

Next j, i

For i = 1 To 10

Print a(i);

Next i

Print

For i = 1 To 10

Print b(i);

Next i

Print

'下面就是合并过程

j = 1

For i = 1 To 10

Do

If a(i) k = k + 1

c(k) = a(i)

Exit Do

Else

k = k + 1

c(k) = b(j)

j = j + 1

If j 10 Then Exit For

End If

Loop

Next i

If i For n = i To 10

k = k + 1

c(k) = a(n)

Next n

End If

If j For n = j To 10

k = k + 1

c(k) = b(n)

Next n

End If

'合并结束

For i = 1 To 20

Print c(i);

Next i

Print

End Sub

Private Sub Form_Load()

Me.AutoRedraw = True

End Sub

4. 怎么两个数组合并一组数,由大到小排列 vb

定义第三个数组,先把其中一个数组写到第三个中,再把第二个数组添加到第三个尾部,再对第三个数组排序。

如:

Private Sub mand3_Click()

Dim a(1 To 5), b(1 To 6), c(1 To 11), i, j As Integer

For i = 1 To 5

a(i) = i

Print a(i);

Next

Print

For i = 1 To 6

b(i) = i + 6

Print b(i);

Next

Print

For i = 1 To 5

c(i) = a(i)

Next

For i = 1 To 6

c(i + 5) = b(i)

Next

For i = 1 To 11

Print c(i);

Next

End Sub

5. 用vb实现两个数相加的问题

Private Sub mand3_Click()

Text1.Text = mand1.Caption mand3.Caption mand2.Caption "="

End Sub

Private Sub mand4_Click()

Text1.Text = mand1.Caption mand3.Caption mand2.Caption "=" CStr(Val(mand1.Caption) + Val(mand2.Caption))

End Sub

Private Sub Form_Load()

mand1.Caption = "1"

mand2.Caption = "2"

mand3.Caption = "+"

mand4.Caption = "="

End Sub


当前文章:vb.net数组合并 vbnet 数组
分享URL:http://scyanting.com/article/ddccecj.html