I got most of it done except one part to it. I also took out the part that picks the word.. I used the compare string command for each guess to see if the letter matches with what the user put in or not.

But I wanted it so that everytime the user makes a wrong guess, then a head or arm or whatever part of the hangman picture shows up till they loose. I tried making a counter paired with a case statement in the else part and also trying to make another If statement with it = 1 or -1 with the compare string function.

Problem is that when it does work, even though its supposed to draw the head first then the arm etc, but instead it draws the head arms etc all it once. It seems like the For Loop is messing it up because it is doing it for the length of the string but I'm not sure what else to do, I tried putting in the Next but that didn't help. I tried to think of something else mathematically but the length of the strings are all different so I'm stuck.

If possible would likethe solution to be really basic stuff that is in the program right now so that I can understand.

Thanks for the help....

I put the *** for where the problem is..

Private Sub cmdStart_Click()
    Const strSentinel As String = "!"
    Dim intSecretWordLength As Integer
    Dim intNumberOfGuesses As Integer
    Dim intLetterPos As Integer
    Dim intInCorrectNumberOfGuesses As Integer
    Dim intWordPickNumber
    Dim strSecretWord As String
    Dim strGuess As String
    Dim strWordGuessedSoFar As String

    intWordPickNumber = RndInt(1, 12)
     strSecretWord = "Boat"
    intSecretWordLength = Len(strSecretWord)
    strWordGuessedSoFar = String(intSecretWordLength, "-")
    lblWord.Caption = strWordGuessedSoFar
    intNumberOfGuesses = 0
    intInCorrectNumberOfGuesses = 0
    Call ResetPic
    strGuess = InputBox("Guess a letter (! to guess word)", "Hangman")
    Do While strGuess <> strSentinel
        intNumberOfGuesses = intNumberOfGuesses + 1
        If lblWord.Caption = strSecretWord Then
            MsgBox "You win"
            Exit Sub
        End If
    For intLetterPos = 1 To intSecretWordLength
        If StrComp(strGuess, Mid(strSecretWord, intLetterPos, 1), vbTextCompare) = 0 Then
                Mid(strWordGuessedSoFar, intLetterPos, 1) = strGuess
         ***   Call CheckPic(strSecretWord) 'Guessed it wrong ****
        End If
        If lnRightLeg.Visible = True Then
            Exit Sub
        End If
    Next intLetterPos
            lblWord.Caption = strWordGuessedSoFar
            strGuess = InputBox("Guess a letter (! to guess word)", "Hangman")
    If strGuess = strSentinel Then
        strGuess = InputBox("Guess the whole word")
    End If
    If StrComp(strGuess, strSecretWord, vbTextCompare) = 0 Then
        MsgBox "You win."
        MsgBox "You lost press ok to see what the word was."
        lblWord.Caption = strSecretWord
    End If
End Sub
Sub ResetPic()
    shpHead.Visible = False
    shpRightHand.Visible = False
    shpLeftHand.Visible = False
    lnBody.Visible = False
    lnLeftArm.Visible = False
    lnRightArm.Visible = False
    lnRightLeg.Visible = False
    lnLeftLeg.Visible = False
End Sub

Sub CheckPic(ByVal strSecretWord As String)

    If shpHead.Visible = False Then
        shpHead.Visible = True
    ElseIf shpHead.Visible = True And lnBody.Visible = False Then
        lnBody.Visible = True
    ElseIf lnBody.Visible = True And lnRightArm.Visible = False Then
        lnRightArm.Visible = True
    ElseIf lnRightArm.Visible = True And lnLeftArm.Visible = False Then
        lnLeftArm.Visible = True
    ElseIf lnLeftArm.Visible = True And shpRightHand.Visible = False Then
        shpRightHand.Visible = True
    ElseIf shpRightHand.Visible = True And shpLeftHand.Visible = False Then
        shpLeftHand.Visible = True
    ElseIf shpLeftHand.Visible = True And lnLeftLeg.Visible = False Then
        lnLeftLeg.Visible = True
    ElseIf lnLeftLeg.Visible = True And lnRightLeg.Visible = False Then
         lnRightLeg.Visible = True
         MsgBox "You lost"
         lblWord.Caption = strSecretWord
    End If
End Sub
'Makes a random number
'Pre: Boundries with the lowest and highest number
'Post: one number that is generated from the boundries
Function RndInt(ByVal intLow As Integer, ByVal intHi As Integer) As Double

    RndInt = Int((intHi - intLow + 1) * Rnd + intLow)

End Function

Why not use a control array and a counter? Every time someone guesses wrong do:

count = count + 1

if NOT controlarray(count).visible and NOT count > Ubound(controlarray()) then
controlarray(count).visible = true
end if

Thats how I did a hangman game back in 98 on my brother's laptop while driving on family vacation from Winnipeg to Minniapolis :)

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.