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
lstHidden.Items.Add(secret)
randomNum = Int(Rnd() * (secret.Length - 1))
guessWord = secret(randomNum)
wordLength = guessWord.Length
lblSecret.Text = " "
Do While wordLength > 0
lblSecret.Text = lblSecret.Text & "_ "
wordLength -= 1
Loop
input = InputBox("Enter a letter", "Letter Guess")
lstOutput.Items.Add(input)]

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

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
  MsgBox(secret.substring(i,1))
Next

Something like that.

This article has been dead for over six months. Start a new discussion instead.