| | |
VB5 hangman help
![]() |
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
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"
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"
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
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
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.
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
Your next step would be to check each array to see that each member matches. You could use a for loop:
The Boolean variable bCorrect will not be left as True unless all letters of the word are correct. That's a start.
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)
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:
VB Syntax (Toggle Plain Text)
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.
Last edited by hkdani; Apr 2nd, 2009 at 11:28 pm.
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Please urgent.Help me with database coding on how to sort out into report.
- Next Thread: Corrupted Install Disk for VB 4.0
Views: 491 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat data database date delete desktop dissertations dissertationthesis edit error excel excelmacro file filename form game group hardware iamthwee image internetfiledownload label list listbox listview login looping mail match metadata microsoft number objectinsert open oracle os prime print printer program prompt random range range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort spectateswamp sql sql2008 sqlserver struct subroutine table tags time timer variable vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows





