VB5 hangman help

Reply

Join Date: Apr 2009
Posts: 2
Reputation: stephiesue02 is an unknown quantity at this point 
Solved Threads: 0
stephiesue02 stephiesue02 is offline Offline
Newbie Poster

VB5 hangman help

 
0
  #1
Apr 2nd, 2009
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"
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: stephiesue02 is an unknown quantity at this point 
Solved Threads: 0
stephiesue02 stephiesue02 is offline Offline
Newbie Poster

Re: VB5 hangman help

 
0
  #2
Apr 2nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: VB5 hangman help

 
0
  #3
Apr 2nd, 2009
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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim strArrayWord(11) as string
  2. 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:
  1. dim bCorrect as Boolean
  2. bCorrect = True
  3. for i = 0 to 11
  4. if strArrayGuessed(i) = strArrayWord(i) then
  5.  
  6. else
  7. bCorrect = False
  8. exit for
  9. End if
  10. next i
  11.  
  12. if bCorrect = True then
  13. ' Success
  14. else
  15. ' Failure
  16. End if

The Boolean variable bCorrect will not be left as True unless all letters of the word are correct. That's a start.
Last edited by hkdani; Apr 2nd, 2009 at 11:28 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC