Hey guys first post here.

Down to business, i have to create a hangman game in VB5 for a Yr 12 assignment. So far i have created a help screen and a word list and a main menu list to navigate to these forms, however i am struggling with the main game section.

So far all i have mangaed to come up with is a flow chart of what i want the program to do:

1. Form loads the wordlist

2. Picks a random word from the wordlist and display it as dashes in a label called "lblWord"

3. Keyboard on Screen enabled (I have an on screen keyboard made of command buttons they also do not work)

4. Everytime a letter button is pressed the game needs to check through the word and if the letter is not in the word load the next image of the hangman picture and decrease the counter by one (counter counts down the amount of incorrect guesses remaining) If the letter is in the word the dash in the word needs to be replaced with the letter.

5. The letter on the on-screen keyboard is disabled

6. If the word is complete user as won

7. If te hangman counter reaches zero the user has lost

This is what i have so far regarding the actual game, i also need help with making the letters work on the on screen keyboard.

Thanks fo any/all help you can give me

Sniper87

Well since you have command buttons on the form you cannot use the form's keypreview property but you can use any of the following events of the command buttons as long as they have the focus...

KeyDown, KeyPress, KeyUp

Now, as for checking if the letter is within the word/phrase you can use the Instr function (see vb's help(*)). To replace the dash with the letter the user guessed you can use the mid function(*). Also, when the user has a word like "Remember" and they guess the "e" you will need to check for each "e" in a loop when using instr.


As for incorrect guesses you will need a form level variable and as each new game starts you will have to reset it there. Then as each incorrect guess is made you will have to decrement the value of the variable prior to displaying its value and prior to testing it for equaling zero (0).

Good Luck

I presume the Command buttons on the screen are linked to letters of the alpabet. If you set up these buttons with the same name so they are indexed it is fairly simple to linke the index of the command button to the letter e.g. Command(0)=A Command(1) =B etc etc

When a button is pressed you can determine the letter as the index will relate to the Ascii number. Command(0) = Ascii 65 = A, Command(1) = 66 = B and so on.

once you know what the letter is you can then loop through your "word" to see if it is present. If it is you replace your dash with the letter.

If it isn't then increment the miss counter by one and load the correct picture. You can do this with a

Select MissCount
case 1: Picture1.load Image1
case 2: Picture1.load Image2
etc etc
end select

Hope this helps ... good luck

www.geocities.com\excelmarksway
Select Games > Hangman.xls
Save the file.
Open Excel then open Hangman.xls

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.