这段程序里面UBound函数LBound函数究竟起什么作用?
数组排序的题,以下是标准答案。我纠结的是这答案里面的UBound(a)和LBound(a)定义出来数组的上下标有什么用处么?这里删掉UBound和LBound的这两句程序...
数组排序的题,以下是标准答案。我纠结的是这答案里面的UBound(a)和LBound(a)定义出来数组的上下标有什么用处么?这里删掉UBound和LBound的这两句程序一样执行。请教这两个函数是在什么情况下是必须的?
Option Base 1
Private Sub Sort(a() As Integer)
Dim Start As Integer, Finish As Integer
Dim i As Integer, j As Integer, t As Integer
Start = LBound(a)
Finish = UBound(a)
For i = 4 To 2 Step -1
For j = 1 To 3
If a(j) > a(j + 1) Then
t = a(j + 1)
a(j + 1) = a(j)
a(j) = t
End If
Next j
Next i
End Sub
Private Sub Command1_Click()
Dim arr1
Dim arr2(4) As Integer
arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text))
For i = 1 To 4
arr2(i) = CInt(arr1(i))
Next i
Sort arr2()
Text1.Text = arr2(1)
Text2.Text = arr2(2)
Text3.Text = arr2(3)
Text4.Text = arr2(4)
End Sub
感谢两位的回复,我也知道这段程序里面这两个函数没用,我想问的是在什么情况下才会用上这东西。 展开
Option Base 1
Private Sub Sort(a() As Integer)
Dim Start As Integer, Finish As Integer
Dim i As Integer, j As Integer, t As Integer
Start = LBound(a)
Finish = UBound(a)
For i = 4 To 2 Step -1
For j = 1 To 3
If a(j) > a(j + 1) Then
t = a(j + 1)
a(j + 1) = a(j)
a(j) = t
End If
Next j
Next i
End Sub
Private Sub Command1_Click()
Dim arr1
Dim arr2(4) As Integer
arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text))
For i = 1 To 4
arr2(i) = CInt(arr1(i))
Next i
Sort arr2()
Text1.Text = arr2(1)
Text2.Text = arr2(2)
Text3.Text = arr2(3)
Text4.Text = arr2(4)
End Sub
感谢两位的回复,我也知道这段程序里面这两个函数没用,我想问的是在什么情况下才会用上这东西。 展开
展开全部
没有用,程序里没用到 Start,Finish这两个变量
Start = LBound(a)
Finish = UBound(a)
Start = LBound(a)
Finish = UBound(a)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询