My name is Stephanie and I have no idea what I am doing. Here is what I need help with:

Modify the code in the btnGuessW_Click event procedure. Add the code to implement the following logic after the existing code:
• Test the value in strWordGuessed against the value in strWordToGuess.
• If incorrect (different values), increment intNumWrongTries.
 When the number of incorrect answers is less than six, display the following string in a MessageBox control:
" That is not correct. You have guessed wrong y times."

Replace y with the number of wrong guesses. Use the following syntax for the MessageBox control:
MessageBox.Show("Text to display")
 When the number of wrong tries equals six, display the message "You lose." and display strWordtoGuess in lblWord. Use the following syntax for the MessageBox control:
MessageBox.Show("Text to display")
• If correct, display strWordtoGuess in lblWord, and display the following message:
"You guessed the word in x tries."
Replace x with the number of guesses.

The code I have so far:
Private Sub btnGuessW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuessW.Click

Dim strWordGuessed = "BASSETT HOUND"
intNumTries += 1
strWordGuessed = txtWord.Text.ToUpper
strWordGuessed(0) = strWordToGuess "B"
strWordGuessed(1) = strWordToGuess "A"
strWordGuessed(2) = strWordToGuess "S"
strWordGuessed(3) = strWordToGuess "S"
strWordGuessed(4) = strWordToGuess "E"
strWordGuessed(5) = strWordToGuess "T"
strWordGuessed(6) = strWordToGuess "T"
strWordGuessed(7) = strWordToGuess "H"
strWordGuessed(8) = strWordToGuess "O"
strWordGuessed(9) = strWordToGuess "U"
strWordGuessed(10) = strWordToGuess "N"
strWordGuessed(11) = strWordToGuess "D"

I have been working on this more and here is the code I have now but still have errors I can't fix. Any suggestions?
Private Sub btnGuessW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuessW.Click

strWordGuessed = txtWord.Text
strWordGuessed = strWordGuessed.ToUpper
intNumTries += 1
If Not strWordToGuess.Contains(strWordGuessed) Then
intNumWrongTries += 1
If intNumWrongTries < 6 Then
MessageBox.Show("That is not correct. You have guessed wrong " & intNumWrongTries & " times.")
Else
MessageBox.Show("You lose.")
lblWord.Text = strWordToGuess
End If
Else
lblWord.Text = strWordToGuess
MessageBox.Show("You guessed the word in " & intNumTries & " tries.")
End If
End Sub

Hangman. I always thought you guessed letters and not words. Have they come up with a new way of playing the game?

I would say that you need to set up a string array that matches the word that you are guessing.

And then I would create a string array for the correct word.

Dim strArrayWord(11) as string
Dim strArrayGuessed(11) as string

Every Time a correct letter (letter not word--little bit of a difference) is guessed, you fill the strArrayGuessed(x) with the proper value.

So, if the word is BassettHound and the user chose 's,' then strArrayGuessed(2) = "s": strArrayGuessed(3) = "s" Your next step would be to check each array to see that each member matches. You could use a for loop:

dim bCorrect as Boolean
bCorrect = True
 for i = 0 to 11  
       if strArrayGuessed(i) = strArrayWord(i) then

       else
             bCorrect = False
             exit for
       End if
next i

if bCorrect = True then
     ' Success
else
     ' Failure
End if

The Boolean variable bCorrect will not be left as True unless all letters of the word are correct. That's a start.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.