到目前为止,我已经在 Virtual Basic 2010 中创建了一个随机发生器,它:
- 将用户在 form2 中输入的人名放入一个数组(以空格分隔)。
- 随机化数组
- 为每个估算的名称显示带有连续数字和句点的数组。
这是源代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim names() As String
Dim i As Integer
Dim j As Integer
Dim tmp As String
Dim txt As String
' Put the names in an array. SaveTitle is all the text saved in Form2
names = Split(My.Settings.SaveTitle, " ")
' Randomize the array.
Randomize()
For i = LBound(names) To UBound(names) - 1
' Pick a random entry.
j = Int((UBound(names) - i + 1) * Rnd() + i)
' Swap the names.
tmp = names(i)
names(i) = names(j)
names(j) = tmp
Next i
' Display the results.
For i = LBound(names) To UBound(names)
txt = txt & vbCrLf & i + 1 & ". " & names(i)
Next i
txt = Mid$(txt, Len(vbCrLf) + 1)
RichTextBox1.Text = txt
End Sub
注意最后一点。我想获取变量 txt 并将其拆分。然后我想取前 10 个名字并在 RichTextBox1 中显示,接下来的 10 个名字在 RichTextBox2 中显示,最后 10 个名字在 RichTextBox3 中显示。
我怎样才能做到这一点?