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!