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
帮帮忙查查看哪儿错的
展开
 我来答
若以下回答无法解决问题,邀请你更新回答
百度网友c34f6e7
2013-07-12 · TA获得超过101个赞
知道小有建树答主
回答量:166
采纳率:88%
帮助的人:110万
展开全部
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
Print
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
Print
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
Print
End If
End Sub
'基本没什么问题,就是你搞混乱了
'数组a()的开始项是a(0),最后一项是a(n)
'只要相应的改一下,就可以
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式