|
-
May 22nd, 2001, 03:32 PM
#1
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
-
May 22nd, 2001, 05:16 PM
#2
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
-
May 22nd, 2001, 05:23 PM
#3
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
-
May 22nd, 2001, 05:59 PM
#4
Frenzied Member
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."
-
May 25th, 2001, 02:43 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|