Like the title says, my VB6 hangman program freezes when I do a test run. I'm not a big expert in Visual Basic (in fact, I'm only a clueless highschool student..) so maybe you can help me. I'm not quite sure what causes freezing to occur, but I've pasted the code below so please take a look.

Dim letteranswer(5) As String
Dim answerlist(10) As String
Dim deathcounter As Integer

Private Sub Form_Load()

'lblLetters are simply dashes that appear under
'picLetter, where the actual letters are shown

For r = 1 To 5
    lblLetter(r).Visible = True
    picLetter(r).Visible = False
Next

'resets the picture to show nothing

Line1.Visible = False
Line2.Visible = False
Line3.Visible = False
shpHead.Visible = False
shpTorso.Visible = False
shpRarm.Visible = False
shpLarm.Visible = False
shpRleg.Visible = False
shpLleg.Visible = False

'contents of answerlist(), the array to choose
'a random word from in the subroutine Getword

answerlist(1) = "HOUSE"
answerlist(2) = "HAPPY"
answerlist(3) = "PUPPY"
answerlist(4) = "BOOKS"
answerlist(5) = "QUEEN"
answerlist(6) = "PRIZE"
answerlist(7) = "CLOSE"
answerlist(8) = "BASIC"
answerlist(9) = "IGLOO"
answerlist(10) = "TRUCK"

Getword

deathcounter = 0     'number of tries

Do Until deathcounter = 9
DeathCount
Loop

End Sub

Private Sub Getword()

Dim answer As String
Dim x As Integer
Dim Index As Integer


'getting a random number from 1 to 10
Randomize
x = Int(Rnd * 10)
If x = 0 Then
x = 1
End If

answer = answerlist(x)

'function for filling in a separate letter
'in an array named letteranswer()

Index = 1
Do Until Index > 6
letteranswer(Index) = Mid(answer, Index, 1)
Index = Index + 1
Loop

End Sub
 
'cmdLetter is an array of buttons with captions
'from A to Z, indexed from 1 to 26

Sub cmdLetter_Click(Index As Integer)
Index = cmdLetter(Index).Index
letterguess = cmdLetter(Index).Caption
letterguess = UCase(letterguess)
  
For Counter = 1 To 5
    If letterguess = letteranswer(Counter) Then
        picLetter(Counter).Print letteranswer(Counter)
    Else: deathcounter = deathcounter + 1
    End If
Next

End Sub


Sub DeathCount(deathcounter As Integer)

Select Case deathcounter
    Case deathcounter = 1
        Line1.Visible = True
    Case deathcounter = 2
        Line2.Visible = True
    Case deathcounter = 3
        Line3.Visible = True
    Case deathcounter = 4
        shpHead.Visible = True
    Case deathcounter = 5
        shpTorso.Visible = True
    Case deathcounter = 6
        shpRarm.Visible = True
    Case deathcounter = 7
        shpLarm.Visible = True
    Case deathcounter = 8
        shpRleg.Visible = True
    Case deathcounter = 9
        shpLleg.Visible = True
End Select

End Sub

I was wondering that if there are more errors that you happen to spot in that code, like syntax and declarations...can you point them out to me and suggest tips? Like for the part of the code that I highlighted in grey. My gut feeling says that there's something wrong with it though I'm not too sure what it is. I'm not too knowledgeable with the syntax of VB at all (as you can see from the code, my knowledge is pretty basic), so any help would be appreciated. x_x

Thanks in advance!

Do Until deathcounter = 9
     DeathCount
Loop

This seams to be where it locks up. You don't increment deathcounter anywhere in the loop or in the deathCount sub.

Look at your code and decide if you really need this function call in a loop.

Oh wow, it did have something to do with it. Thanks! I simply merged it.

I do have a new problem however. It doesn't seem to show that I have made a wrong answer. I highlighted my suspicions on black, and I can't see why the Else statement isn't working...

Dim letteranswer(5) As String
Dim letterguess As String
Dim answerlist(10) As String
Dim deathcounter As Integer
Dim answer As String

Private Sub Getword()
Dim x As Integer
Dim Index As Integer
Dim Index2 As Integer

'getting a random number from 1 to 10
Randomize
x = Int(Rnd * 10)
If x = 0 Then
x = 1
End If

answer = answerlist(x)

'function for filling in a separate letter
'in an array named letteranswer()

Index = 1
Do Until Index > 5
letteranswer(Index) = Mid(answer, Index, 1)
Index = Index + 1
Loop

'setting the each answer to each label

For Index2 = 1 To 5
lblAnswer(Index2).Caption = letteranswer(Index2)
Next

End Sub
 
Private Sub cmdLetter_Click(Index As Integer)
Dim Counter As Integer

Index = cmdLetter(Index).Index
letterguess = cmdLetter(Index).Caption
letterguess = UCase(letterguess)
    
For Counter = 1 To 5
    If letterguess = letteranswer(Counter) Then
        lblAnswer(Counter).Visible = True
    Else
    
deathcounter = deathcounter + 1
Select Case deathcounter
    Case deathcounter = 1
        Line1.Visible = True
    Case deathcounter = 2
        Line2.Visible = True
    Case deathcounter = 3
        Line3.Visible = True
    Case deathcounter = 4
        shpHead.Visible = True
    Case deathcounter = 5
        shpTorso.Visible = True
    Case deathcounter = 6
        shpRarm.Visible = True
    Case deathcounter = 7
        shpLarm.Visible = True
    Case deathcounter = 8
        shpRleg.Visible = True
    Case deathcounter = 9
        shpLleg.Visible = True
End Select
    
    
    End If
Next

End Sub

Private Sub cmdQuit_Click()
frmEgame1.Hide
frmMain.Show
End Sub


Private Sub Form_Load()
Dim r As Integer

For r = 1 To 5
    lblLetter(r).Visible = True
    lblAnswer(r).Visible = False
Next

Line1.Visible = False
Line2.Visible = False
Line3.Visible = False
shpHead.Visible = False
shpTorso.Visible = False
shpRarm.Visible = False
shpLarm.Visible = False
shpRleg.Visible = False
shpLleg.Visible = False

answerlist(1) = "HOUSE"
answerlist(2) = "HAPPY"
answerlist(3) = "PUPPY"
answerlist(4) = "BOOKS"
answerlist(5) = "QUEEN"
answerlist(6) = "PRIZE"
answerlist(7) = "CLOSE"
answerlist(8) = "BASIC"
answerlist(9) = "IGLOO"
answerlist(10) = "TRUCK"

deathcounter = 0

Getword


End Sub

What's wrong now?

Seams like the Else never fires. Try something like this. . . and step through the program when purposely clicking on a wrong letter to see why the else never gets executed.

dim bGoodGuess as boolean

For Counter = 1 To 5
    If letterguess = letteranswer(Counter) Then
        lblAnswer(Counter).Visible = True
bgoodguess = true
    end if
next
    
if not bGoodGuess then
deathcounter = deathcounter + 1
Select Case deathcounter
    Case deathcounter = 1
        Line1.Visible = True
    Case deathcounter = 2
        Line2.Visible = True
    Case deathcounter = 3
        Line3.Visible = True
    Case deathcounter = 4
        shpHead.Visible = True
    Case deathcounter = 5
        shpTorso.Visible = True
    Case deathcounter = 6
        shpRarm.Visible = True
    Case deathcounter = 7
        shpLarm.Visible = True
    Case deathcounter = 8
        shpRleg.Visible = True
    Case deathcounter = 9
        shpLleg.Visible = True
End Select
    
    
    End If
This article has been dead for over six months. Start a new discussion instead.