Reputation: 43
Sub guessLetter(letterGuess As String)
Dim lengthOfSecretWord As Integer
lengthOfSecretWord = Len(Secret_word) - 1
tempWord = ""
Dim letterPosition As Integer
For letterPosition = 0 To lengthOfSecretWord
If Mid(Secret_word, letterPosition, 1) = letterGuess Then
tempWord = tempWord & letterGuess
Else
tempWord = tempWord & Mid(lblTempWord, letterPosition, 1)
End If
Next
lblTempWord = tempWord
End Sub
I have runtime error "5" and the problem in line IF, i'm stuck to declare Secret_word.substr(letterPosition, 1)
on vb6, first i try write Secret_word.substr(letterPosition, 1)
but it can't then i try to manipulate that then runtime error 5 came
Upvotes: 1
Views: 3644
Reputation:
The Mid Function in VB (like most things in VB) is 1-indexed, not 0-indexed.
I'm assuming you're familiar with other languages in which you would loop from 0 to Len(String)-1, but VB thinks you'll find it more intuitive to loop from 1 to Len(String).
Refer to the description and example in the documentation for more details.
Upvotes: 2