| re: Hangman Game
make intLength = mstrword.length - 1 instead of mstrword.length.
For example,
"happy" has 5 letters, so it's length is 5.
"happy" has letters at index 0, 1, 2, 3, 4.
It's last available index is it's length - 1.
"Steven Smith" <Steven.Smith@emailaccount.com> wrote in message
news:411801c37646$f89b9540$a101280a@phx.gbl...[color=blue]
>[color=green]
> >-----Original Message-----
> >Hi guys[/color]
>
> Heh where do I start this time :)
>
> first of all thanks for your responses
>
> I've managed to implement the sugestions from Fergus,
> Herfried & jeremy, however doing this has highlighted
> another problem in the following For...Next loop.
>
> since the letter count for the game is now dynamic the
> index range which is searched to determine if the chosen
> letter appears in the secret word also has to be dynamic
>
> i.e for intIndex = 0 to 4
>
> was fine for a consistent 5 letter word but now obviously
> this is no use now.
>
> Sooooo what I thought I would do is pull the string
> length from mstrWord.length and assign the value to an
> integer as follow's:
>
> intLength = mstrword.length
> for intIndex = 0 to intlength
>
> however when the game begins and a letter is chosen the
> following line kicks back with the error 'Index and
> length must refer to a location within the string':
>
> strCharacter = mstrWord.Substring(intIndex, 1)
>
> this out of range error doesn't make sense to me as the
> loop should check the index range of 0 to the value of
> intLength.
>
>
>
>
> ///
> 'search for the selected letter in the secret word
> For intIndex = 0 To 4
> 'assign current character to the strCharacter
> variable
> strCharacter = mstrWord.Substring(intIndex, 1)
> 'determine whether or not the current
> character matches the selected letter
> If strCharacter = objLetterLabel.Text Then
> 'replace appropriate dash/es in the
> strPartialWord variable
> Mid(strPartialWord, intIndex + 1) =
> objLetterLabel.Text
> 'indicate that a replacement was made
> blnReplaced = True
> End If
> Next intIndex
> ///
>
>
> now my head hurts, but I'm determined to make this
> work... :)
>
> Regards Steve
>
>
>[/color] |