如果只是为了实现功能,那就ChatGPT吧,下列示例ChatGPT给出的代码:
Private Sub Command1_Click()
Dim arrNames() As String
Dim i As Integer
Dim strName As String
Dim intIndex As Integer
Dim strOutput As String
'Read names from file
Open "1.TXT" For Input As #1
Do Until EOF(1)
Line Input #1, strName
If strName <> "" Then
ReDim Preserve arrNames(i)
arrNames(i) = strName
i = i + 1
End If
Loop
Close #1
'Randomly sort names
Randomize
For i = LBound(arrNames) To UBound(arrNames)
intIndex = Int((UBound(arrNames) - i + 1) * Rnd + i)
strName = arrNames(i)
arrNames(i) = arrNames(intIndex)
arrNames(intIndex) = strName
Next i
'Display names with index
For i = LBound(arrNames) To UBound(arrNames)
strOutput = strOutput & i + 1 & ". " & arrNames(i) & vbCrLf
Next i
Text1.Text = strOutput
End Sub