永发信息网

VB排text1.数字顺序 ,不知道哪里错了

答案:1  悬赏:0  手机版
解决时间 2021-05-06 14:15
  • 提问者网友:放下
  • 2021-05-06 07:03
Private Sub Command1_Click()
Dim str() As String
Dim num() As Integer
Dim max, i, n, j ,r As Integer
str() = Split(Text1.Text, ",")
n = UBound(str)
ReDim num(n)
For i = 0 To n
num(i) = CInt(str(i))
Next i
For r = 0 To n - 1
For j = i To n
If num(i) > num(j) Then
max = num(i)
num(i) = num(j)
num(j) = max
Else
End If
Next j
Next r
For r = 1 To n
Print num(r)
Next r
End Sub
最佳答案
  • 五星知识达人网友:長槍戰八方
  • 2021-05-06 08:11

Private Sub Command1_Click()
Dim str() As String
Dim num() As Integer
Dim max, i, n, j, r As Integer
str() = Split(Text1.Text, ",")
n = UBound(str)
ReDim num(n)
For i = 0 To n
num(i) = CInt(str(i))
Next i


For r = 0 To n - 1
For j = r To n
If num(r) > num(j) Then
max = num(r)
num(r) = num(j)
num(j) = max
Else
End If
Next j
Next r


For r = 1 To n
Print num(r)
Next r
End Sub


上面的是正确的



你是把里面循环的r写成i了



For j = i To n
If num(i) > num(j) Then
max = num(i)
num(i) = num(j)
num(j) = max

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯