Well we have a hangman project on vb to do...


I m stuck on a part and it's pissing me off

Basically , it's a simple hangman game .


I will upload my .vbp and .frm , in case someone wants to help me and find my problem.


What i m really stuck on , is when I click "I" for example, the I appears really good , with all the underscores of the characters that remains.

However , if I click on another Letter, like "N" , it erases the "I" part, and does the job for the "N" position

Also , another problem , is that when there are two letters, I can't seem to find a function to do double check ... I tried a different method using arrays and tables, but my lack of knowledge in this domains clearly won't help me


I would appreciate any help, and here's the files:

http://www.speedyshare.com/files/20340171/Hang_man.frm ( the frm )

http://www.speedyshare.com/files/20340181/Hang_Man.vbp ( the project , but off course you would know that )




Thank you very much in advance and hope I am not bothering
Where i am now, i dont have VB but i took a look @ ur code
Private Sub cmdButton_Click(Index As Integer)
Dim c As Integer
Dim pos As Integer
Dim i As Integer
Dim resu As String

cmdButton(Index).Enabled = False



For pos = 1 To Len(word)
If InStr(pos, word, cmdButton(Index).Caption) > 0 Then
c = InStr(pos, word, cmdButton(Index).Caption)
lbl.Caption = ""
     For i = 1 To pos - 1
      
      lbl.Caption = lbl.Caption & " _ "
      Next i
      
      lbl.Caption = lbl.Caption & cmdButton(Index).Caption
      
     For i = pos + 1 To Len(word)
     
      lbl.Caption = lbl.Caption & " _ "
     Next i
     
    
 End If
Next pos
ur code will NEVER display more than 1 letter -_-
ur always filling the caption with "_" and the letter the guy just pressed, in case it was found.

you should initially fill it with "_" and then only substitute the found letter, not refill it all.
+ u could have used the "KeyPressed" event :)

If i found my VB6 CD in here, i'll give it a shot and work a bit on it :D
Coffee brake time and VB is here, i think im gona do a small hangman game :P

Edit: if u decide to rename ur form @ the last minute ...at least rename it in the project ;)
Thx padre !

Well I am here to learn , and I did realize the error in my code, this is why I posted in here, in order for someone to aid me a bit , i ll check your prog.

And about the form , I noticed it after i uploaded that I couldn't rename it.


Btw i opened the file, how do you play your game ? :P lol
Thank you for the code, I will study it well, seems genuine enough for me :P



Edit :


If C = Mid$(Hang_Word, i, 1) Then Hang_Display = Mid$(Hang_Display, 1, 2 * i - 2) & C & " " & Mid$(Hang_Display, 2 * i, Len(Hang_Display) - 2 * i)



What does it do , I don't understand it at all, and I m persuaded this is the code i need to finish off my version

This is one wicked code
correct, that's the mistake u had.
Every time u refill the display with _ and the letter the guy just pressed and by that, u erase the previous one.
the line above check for a matching pressed character to the original string (Hang_Word), and for every matching one, it will replace the "_ " with the letter. Mid takes everything before our letter, we append our character and then the second mid takes the rest of it and replaces it back into to the original displayed string (Hang_Display)

There are better ways to do it, it's just the first to come out of my mind and that matches the way u worked on ur code :)
I don't think I understand the approach of the 2*i
-_-

it's because for every letter i have 2 characters to display ... a "_" and a " " :P
Lol , thanks man , 3azabnek !

I ll try understanding it