VERSION 5.00 Begin VB.Form frmHangman Caption = "Hangman" ClientHeight = 2556 ClientLeft = 3948 ClientTop = 2736 ClientWidth = 3744 LinkTopic = "Form1" ScaleHeight = 2556 ScaleWidth = 3744 Begin VB.CommandButton cmdDone Caption = "Done" Height = 372 Left = 2640 TabIndex = 2 Top = 2040 Width = 972 End Begin VB.CommandButton cmdPlayGame Caption = "Play Game" Height = 372 Left = 2640 TabIndex = 1 Top = 1560 Width = 972 End Begin VB.Label lblWord Alignment = 2 'Center BeginProperty Font Name = "MS Sans Serif" Size = 13.8 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 372 Left = 480 TabIndex = 0 Top = 480 Width = 2652 End End Attribute VB_Name = "frmHangman" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' Chapter 6 Hangman Case Study ' 3/99 Option Explicit Private Sub cmdPlayGame_Click() Const strSentinel As String = "!" Dim strSecretWord As String, intSecretWordLength As Integer Dim intNumberOfGuesses As Integer Dim strGuess As String, strWordGuessedSoFar As String Dim intLetterPos As Integer strSecretWord = "magic" intSecretWordLength = Len(strSecretWord) strWordGuessedSoFar = String(intSecretWordLength, "-") lblWord.Caption = strWordGuessedSoFar intNumberOfGuesses = 0 strGuess = InputBox("Guess a letter (! to guess word)", "Hangman") Do While strGuess <> strSentinel intNumberOfGuesses = intNumberOfGuesses + 1 For intLetterPos = 1 To intSecretWordLength If StrComp(strGuess, Mid(strSecretWord, intLetterPos, 1), vbTextCompare) = 0 Then Mid(strWordGuessedSoFar, intLetterPos, 1) = strGuess End If Next intLetterPos lblWord.Caption = strWordGuessedSoFar strGuess = InputBox("Guess a letter (! to guess word)", "Hangman") Loop If strGuess = strSentinel Then strGuess = InputBox("Guess the word") End If If StrComp(strGuess, strSecretWord, vbTextCompare) = 0 Then MsgBox "You win! It took you " & intNumberOfGuesses & " guesses." Else MsgBox "You lose. Press OK to display secret word." End If lblWord.Caption = strSecretWord End Sub Private Sub cmdDone_Click() Unload Me End Sub