user2893915
user2893915

Reputation: 1

How to generate random alphabet (vowels only)

My Current Code

Public Class Form1

Dim randomObject As New 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

End Class

*randomObject.Next(65, 91) ' which means it take generate random alpha to A-Z only according to asciicode , what about only vowels ?*

Can i use something like array Dim vowels As String() = {"A", "E", "I", "O", "U"} then generate the random alphabet from my string for me to guess later

Upvotes: 0

Views: 536

Answers (2)

dbasnett
dbasnett

Reputation: 11773

or just use a string

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

Upvotes: 0

hallie
hallie

Reputation: 2845

You can do something like

Dim vowels As String() = {"A","E","I","O","U"}
Dim i As Int32 = randomObject.Next (0, 5)
Return vowels(i)

Upvotes: 3

Related Questions