【发布时间】:2016-07-24 19:00:01
【问题描述】:
谁能告诉我这是怎么回事?
当按下Button1 时,我试图在Label1 中出现一个随机问题。我只希望每个问题出现一次。
Dim Qtn(4) As String
Private Sub LoadQs()
Qtn(0) = "What is 1 + 10?"
Qtn(1) = "What is 1 + 11?"
Qtn(2) = "What is 1 + 12?"
Qtn(3) = "What is 1 + 13?"
Qtn(4) = "What is 1 + 14?"
End Sub
Private Sub RndQtn()
Dim list As New ArrayList
For i As Integer = 0 To 4
'Add the numbers to the collection.
list.Add(i)
Next i
Dim randomValue As New Random
Dim index As Integer
Dim item As Object
'Display the items in random order.
While list.Count > 0
'Choose a random index.
index = randomValue.Next(0, Qtn.Length)
'Get the item at that index.
item = list(index)
'Remove the item so that it cannot be chosen again.
list.RemoveAt(index)
'Display the item.
Label1.Text = Qtn(item)
End While
End Sub
【问题讨论】:
-
欢迎来到 Stack Overflow!我尽可能地编辑了你的问题。但是,添加代码和描述,以便更多具有该主题知识的人看到它。请在您遇到的特定错误消息中进行编辑,以防有必要识别特定问题。也看看this question。祝你好运!
标签: vb.net vb.net-2010