I am currently trying to program a hangman game as a final project - not a final grade or test. I have started this project but I am now stuck. The following is the code that has been started:
Dim secret() As String = {"fall", "spring", "winter", "summer", "thanksgiving"}
Dim input As Char
Dim guessWord As String
Dim randomNum As Integer
Dim wordLength As Integer
randomNum = Int(Rnd() * (secret.Length - 1))
guessWord = secret(randomNum)
wordLength = guessWord.Length
lblSecret.Text = " "
Do While wordLength > 0
lblSecret.Text = lblSecret.Text & "_ "
wordLength -= 1
input = InputBox("Enter a letter", "Letter Guess")

The problem is trying to get the users guess letter to search the secret letter and input in correct place. Can someone please help?

Thanks in advance

9 Years
Discussion Span
Last Post by terivo

There are many ways to do that. But essentially what you are trying to do is look for single characters in your secret (as you put it) word.

Using the substring method, is one way to isolate individual characters.


I know this may be basic, but I am not sure of how to do this substring. Any help on this would be appreciated. We did not cover much on substrings...just basic code.


Before writing any code try thinking about how you would do it in plain English...

Prompt user for a letter
Allow the system to choose a secret word
Loop through each character in word checking if it is the same as the users
If it is the same show it otherwise show a blank space

Looping through each character in a string

Dim secret As String = "crap"
Dim I As Integer
For I = 0 to I < secret.Length - 1

Something like that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.