BeginGetTodoItems' of type
用户会输入一个字母,它将检查该字母是否包含在变量listWords中,我认为我过度思考这个并且这是一个简单的解决方案,但我不能为我的生活思考如何实现这一点。
答案 0 :(得分:0)
这是一个奇怪的请求。 给定一个Windows窗体上的按钮,下面是代码来做你想要的。 只需更换" a"用你的实际输入。
考虑将随机单词生成和角色的实际测试分成两个单独的部分。
祝你好运Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim randomWord As String = GetRandomWord()
Dim userInput As Char = "a"
If randomWord.Contains(userInput) Then
MessageBox.Show("Yes, the word '" + randomWord + "' DOES contain the letter '" + userInput + "'")
Else
MessageBox.Show("No, the word '" + randomWord + "' DOES NOT contain the letter '" + userInput + "'")
End If
End Sub
Private Function GetRandomWord() As String
Dim listWords(4) As String
listWords(0) = "juicy"
listWords(1) = "aaron"
listWords(2) = "power"
listWords(3) = "weigh"
listWords(4) = "public"
Dim Index As Integer = GetRandomNumber(listWords.Length - 1)
Return listWords(Index)
End Function
Private Function GetRandomNumber(maxValue As Integer) As Integer
'Math.Ceiling rounds up to the nearest whole number
Return Math.Ceiling(Rnd() * maxValue)
End Function
End Class