这就是我到目前为止所拥有的;
Function myChoice(ByVal opt1 As String, ByVal opt2 As String, ByVal opt3 As String, ByVal opt4 As String)
Dim choose As String
Dim mynum As Integer
Randomize()
mynum = Int(Rnd() * 4 + 1)
Select Case mynum
Case 1
choose = opt1
Case 2
choose = opt2
Case 3
choose = opt3
Case 4
choose = opt4
End Select
myChoice = choose
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(myChoice("Red", "Orange", "Yellow", "Green"))
End Sub
我想要做的不是将 ByVal opt1 作为字符串,ByVal op2 ..... 如果我说 100 种颜色,我如何使函数有 100 个 opt's 并且有 100 个“case”事件而无需全部输入在?
我觉得我可能需要一个循环,也可能需要一个数组,但除此之外,我很难过。
谢谢。