vb中怎么将list中的数据排序显示在另一个list中
我的程序是PrivateSubCommand5_Click()dgs=Val(Text3.Text)Fori=1TodgsReDimd(i)d(i)=List1.List...
我的程序是
Private Sub Command5_Click()
dgs = Val(Text3.Text)
For i = 1 To dgs
ReDim d(i)
d(i) = List1.List(i - 1)
Next i
For i = 1 To dgs
ReDim c(i) As Single
m = Int(Rnd * dgs) + 1
c(i) = List1.List(m - 1)
For j = m To dgs - 1
d(j) = d(j + 1)
Next j
dgs = dgs - 1
List2.AddItem c(i)
Next i
End Sub
运行的结显示的不是list1中的数据组合,请教各位大虾 展开
Private Sub Command5_Click()
dgs = Val(Text3.Text)
For i = 1 To dgs
ReDim d(i)
d(i) = List1.List(i - 1)
Next i
For i = 1 To dgs
ReDim c(i) As Single
m = Int(Rnd * dgs) + 1
c(i) = List1.List(m - 1)
For j = m To dgs - 1
d(j) = d(j + 1)
Next j
dgs = dgs - 1
List2.AddItem c(i)
Next i
End Sub
运行的结显示的不是list1中的数据组合,请教各位大虾 展开
2个回答
展开全部
你的什么排序用得着搞这么复杂吗
你里面有很明显的几个问题
redim 重定义后数组里面的内容会丢失,如这段
For i = 1 To dgs
ReDim d(i)
d(i) = List1.List(i - 1)
Next i
你最后的d(dgs)里面是有值的 其他都是空的,因为每循环一次你就重定义一次。
你看下是不是你要的效果
Private Sub Command1_Click()
Dim Sflag As Boolean
Randomize
List2.Clear
Dim lCount As Integer
lCount = List1.ListCount
ReDim s(lCount)
For i = 0 To UBound(s) - 1
Do
s(i) = Int(Rnd * lCount) 'list1.listindex从0开始
Sflag = False
For j = 0 To i - 1
If s(j) = s(i) Then
Sflag = True
End If
Next
If Sflag = False Then Exit Do
Loop
List2.AddItem List1.List(s(i))
Next
End Sub
你里面有很明显的几个问题
redim 重定义后数组里面的内容会丢失,如这段
For i = 1 To dgs
ReDim d(i)
d(i) = List1.List(i - 1)
Next i
你最后的d(dgs)里面是有值的 其他都是空的,因为每循环一次你就重定义一次。
你看下是不是你要的效果
Private Sub Command1_Click()
Dim Sflag As Boolean
Randomize
List2.Clear
Dim lCount As Integer
lCount = List1.ListCount
ReDim s(lCount)
For i = 0 To UBound(s) - 1
Do
s(i) = Int(Rnd * lCount) 'list1.listindex从0开始
Sflag = False
For j = 0 To i - 1
If s(j) = s(i) Then
Sflag = True
End If
Next
If Sflag = False Then Exit Do
Loop
List2.AddItem List1.List(s(i))
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询