求VB程序()
求VB程序,实现以下功能:1、输入一组姓名
2、点一个按钮,对这些姓名随机排序(或者给每个姓名加个序号),屏幕显示出来
2023-03-23 10:43
2023-03-23 11:37
程序代码:
Private Sub Command1_Click()
s = Split(Trim(Text1.Text), vbCrLf)
sSize = UBound(s)
For i = 0 To sSize
s(i) = i + 1 & " " & s(i)
Next i
For i = 0 To sSize
k = Int(Rnd() * sSize) + 1
t = s(i)
s(i) = s(k)
s(k) = t
Next i
sr = ""
For i = 0 To sSize
sr = sr & s(i) & vbCrLf
Next i
Text2.Text = sr
End Sub
2023-03-23 15:40
2023-03-29 09:59
2023-03-29 11:23
2023-03-29 11:25

2023-03-29 17:40
程序代码:Private Sub Command1_Click()
Dim Count As Long, P As Long
Dim Names() As Variant
Dim Index() As Long
Names() = Array("A", "B", "C", "D", "E")
Count = UBound(Names)
Call GetRandoms(Count, Index())
For P = 0 To Count
Debug.Print Names(Index(P)), Index(P)
Next
Erase Names(), Index()
End Sub
Private Sub GetRandoms(ByVal Count As Long, Randoms() As Long)
Dim iRnd As Long, P As Long
Dim Exists() As Byte
ReDim Exists(Count) As Byte, Randoms(Count) As Long
VBA.Randomize
Do
iRnd = Int((Count + 1) * VBA.Rnd())
If Exists(iRnd) = 0 Then
Exists(iRnd) = 1
Randoms(P) = iRnd
P = P + 1
End If
Loop Until P > Count
Erase Exists()
End Sub
2023-04-05 10:24