vb控件数组的使用
PrivateSubCommand1_Click(indexAsintegr)DimaAsVarianta=Array(56,90,-123,58,5,10,100,53...
Private Sub Command1_Click(index As integr)
Dim a As Variant
a = Array(56, 90, -123, 58, 5, 10, 100, 53, 66, 518)
n = UBound(a)
If index = 0 Then
For i = 1 To n - 1
imin = i
For j = i + 1 To n
If a(imin) > a(j) Then imin = j
Next j
t = a(i): a(i) = a(imin): a(imin) = t
Next i
For i = 1 To n
Print a(i);
Next i
Print
ElseIf index = 1 Then
For i = 1 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
For i = 1 To n
Print a(i);
Next i
Print
Else
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To n
Print a(i);
Next i
Print
End If
End Sub
帮帮忙查查看哪儿错的 展开
Dim a As Variant
a = Array(56, 90, -123, 58, 5, 10, 100, 53, 66, 518)
n = UBound(a)
If index = 0 Then
For i = 1 To n - 1
imin = i
For j = i + 1 To n
If a(imin) > a(j) Then imin = j
Next j
t = a(i): a(i) = a(imin): a(imin) = t
Next i
For i = 1 To n
Print a(i);
Next i
ElseIf index = 1 Then
For i = 1 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
For i = 1 To n
Print a(i);
Next i
Else
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To n
Print a(i);
Next i
End If
End Sub
帮帮忙查查看哪儿错的 展开
若以下回答无法解决问题,邀请你更新回答
展开全部
mark,一会电脑上给你改一下
追问
O(∩_∩)O谢谢!
追答
Dim a As Variant
a = Array(56, 90, -123, 58, 5, 10, 100, 53, 66, 518)
n = UBound(a)
If Index = 0 Then
For i = 0 To n - 1
imin = i
For j = i + 1 To n
If a(imin) > a(j) Then imin = j
Next j
t = a(i): a(i) = a(imin): a(imin) = t
Next i
For i = 0 To n
Print a(i);
Next i
ElseIf Index = 1 Then
For i = 0 To n - 1
For j = i + 1 To n
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
For i = 0 To n
Print a(i);
Next i
Else
For i = 0 To n
For j = 0 To n - i - 1
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 0 To n
Print a(i);
Next i
End If
End Sub
'基本没什么问题,就是你搞混乱了
'数组a()的开始项是a(0),最后一项是a(n)
'只要相应的改一下,就可以
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询