0

我当前的代码

公开课形式1

将 randomObject 调暗为新的 Random()

Dim alphaRand As Integer = randomObject.Next(65, 91)

 Dim alpha As String = Me.textAlphabet.Text.ToUpper

    Dim asciicode As Integer = Asc(alpha)

    If asciicode = alphaRand Then
        Me.lblAlphaResult.Text = "Congratulation! Your guess:  " & textAlphabet.Text & " is correct,you win"
        Me.cmdAlphaNewGame.Enabled = True
        Me.cmdAlphaGuess.Enabled = False
    ElseIf asciicode < alphaRand Then
        Me.lblAlphaResult.Text = "You guess is too low.Try again"
    ElseIf asciicode > alphaRand Then
        Me.lblAlphaResult.Text = "Your guess is too high.Try again"
    End If
End Sub

结束类

* randomObject.Next(65, 91) ' 这意味着它只根据 asciicode 生成 AZ 的随机 alpha ,那么只有元音呢?*

我可以使用数组 Dim vowels As String() = {"A", "E", "I", "O", "U"} 之类的东西,然后从我的字符串中生成随机字母供我稍后猜测

4

2 回答 2

3

你可以做类似的事情

Dim vowels As String() = {"A","E","I","O","U"}
Dim i As Int32 = randomObject.Next (0, 5)
Return vowels(i)
于 2013-10-18T09:17:54.207 回答
0

或者只使用一个字符串

Dim randomObject As New Random
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim vowels As String = "AEIOU"

    Dim vowelpicked As String

    vowelpicked = vowels.Substring(randomObject.Next(vowels.Length), 1)

    Debug.Write(vowelpicked)
End Sub
于 2013-10-18T11:26:58.837 回答