Results 1 to 5 of 5

Thread: hangman Game

  1. #1
    antma
    Guest

    hangman Game

    Hi
    Im kinda a newbie and would like some help Please!!

    Im writing a hangman Game for 2 players.
    How it works is the user is prompted for a new word by means of a INput box . The assiged label then displays the word as "******" .
    Now what I want 2 know is how to set the Eg: Word equel to an
    array Eg: Secret word.

    Eg:

    word = inputbox (".....")


    now how do i go about setting this returned value = to an array

    Eg :secretword()
    so that the guesses can be compared to that array


    please help

    Thanx

  2. #2
    Megatron
    Guest
    This will take a string from an InputBox and split it into an Array
    Code:
    Dim Word As String
    Dim vWord() As String
    
    Word = InputBox("Enter word")
    
    For i = 1 To Len(Word)
        ReDim Preserve vWord(i - 1)
        vWord(i - 1) = Mid(Word, i, 1)
    Next i

  3. #3
    Megatron
    Guest
    And you can use this function for the guessing of a letter:
    Code:
    Function GuessLetter(ByVal sLetter As String, vArray As Variant)
        For i = 0 To UBound(vArray)
            'Make sure that only the 1st letter is chosen
            If vArray(i) = Left(sLetter, 1) Then MsgBox "Yes": Exit Function
        Next i
        MsgBox "No"
    End Function
    Usage:
    Code:
    GuessLetter "a", vArray

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    This is no big deal, but it's probably better to ReDim the array only once:
    Code:
    Dim Word As String
    Dim vWord() As String
    
    Word = InputBox("Enter word")
    
    ReDim vWord(Len(Word) - 1)
    
    For i = 1 To Len(Word)
        vWord(i - 1) = Mid(Word, i, 1)
    Next i
    Like I said, no biggie.
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    Megatron
    Guest
    Yeah, you're right; it will probably save time in the long run.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width