nauman612 said:
can any one plz help me create hangman word game on MS Excel???
thanking you
nauman
If all you want is a working copy of Hangman to run in Excel, then by
all means go to Walkenbach's site. It you want to make your own program
(I certainly would - the only way to learn anything is to reinvent lots
of wheels), here are a few suggestions:
1) Learn VBA (a silly suggestion, but your post does not indicate how
much VBA you know. A hangman program isn't all that hard, but it isn't
trivial either, so isn't a good first program. *If* you are beginner in
VBA I would recommend shelving the idea until you have plowed through a
book.) This suggestion is relevant if the following suggestions seem
completely obscure.
2) The main sheet (that the user would see) could be formatted so that
every other column has a narrow width. You would need to write a macro
to do this. Turn off gridlines and row/column labels at the end. The
cells which are to hold the word could be underlined. The point of the
narrow columns is to introduce spaces between the underlined cells.
Your main hangman program would need to start by initializing the main
sheet - clearing any previous data and underlining the right number of
cells to indicate how many letters the user needs to guess.
3) Draw the gallows and completely hanged main on the main sheet.
Change the name of each shape that you want to appear to (say)
"hangman1", "hangman2", etc, with the numbers indicating the order you
want them to appear. Change the visibility of each of these shapes to
false. Then, your main program might have something like this:
If CorrectGuess = False Then
NumWrong = NumWrong + 1
Sheets(1).Shapes("hangman" & NumWrong).Visible = True
If NumWrong > MaxNumWrong Then
MsgBox "Sorry, you lose!"
Done = True
End If
End If
4) Store the actual words say in Column A of a sheet called "words",
with maybe the number of words stored in B1. For testing purposes you
could just write a couple of dozen. Afterwards, you could look into
writing a macro that would take a text file consisting of thousands of
words (say a listing of the 1000 most common words in English - surely
google can find such a thing) and write them into the worksheet. If you
are lucky, you may not even need to write a macro if Excel itself can
import the data. The your main code would have something like
NumWords = Sheets("words").Range("B1").Value
i = Int(NumWords * Rnd())
Word = Range(Sheets("words").Range("A1").Offset(i).Value
5) The main loop (maybe a Do Until Done loop) could consist of using an
inputbox to ask the user for a guess. Using InStr() to check if the
guessed letter occurs in the word then acting accordingly: if a correct
guess then making that letter visible and incrementing a variable
CorrectGuesses and comparing it to the length of the word to see if
they have won; if a wrong guess then displaying the incorrect guess in
the spreadsheet and making another shape visible (see above).
Hope that helps. If you decide to go that route, don't hesitate to ask
more questions if you get stuck at specific things (like how do you
change the name of a shape or use InStr()).
-John Coleman