Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Hangmen Game Help
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dragoon




PostPosted: Mon Jun 02, 2003 7:33 pm   Post subject: Hangmen Game Help

Iam having trouble getting my hangmen game to work. I want it to output a message box that says "Head" the first time when the user gets a answer wrong then "Body" if they get the second answer wrong and so on.
code:
Dim choice1(0 To 4) As String
Dim Word As String
Dim Letter As String
Dim counter As Integer

Private Sub cmdGuess_Click()
For I = 1 To Len(Word)
Letter = Mid(Word, I, 1)
Call Check
Next I
lblPicked.Caption = lblPicked.Caption & txtLetter & ","
If counter = Len(Word) Then
MsgBox "You guessed all the letters"
End If
End Sub

Private Sub Check()
If Letter = txtLetter Then
MsgBox txtLetter & " " & "is in the word"
lblRight.Caption = lblRight.Caption & txtLetter & ","
counter = counter + 1
End If
End Sub

Private Sub Form_Load()
choice1(0) = "cat"
choice1(1) = "dog"
choice1(2) = "mouse"
choice1(3) = "rat"
choice1(4) = "toronto"
Randomize
Word = choice1(Int(Rnd * 5)) 'Randomizes
counter = 0
If Word = "cat" Then
lblCat = "Animal"
lblLetters = "3 Letters"
End If
If Word = "dog" Then
lblCat = "Animal"
lblLetters = "3 Letters"
End If
If Word = "mouse" Then
lblCat = "Animal"
lblLetters = "5 Letters"
End If
If Word = "rat" Then
lblCat = "Animal"
lblLetters = "3 Letters"
End If
If Word = "toronto" Then
lblCat = "Place"
lblLetters = "7 Letters"
End If
End Sub
Sponsor
Sponsor
Sponsor
sponsor
MysticAngel




PostPosted: Mon Jun 02, 2003 8:33 pm   Post subject: (No subject)

k i dont know how u frame the code for wat u asked but u there were a few error in ur program. When u call an object just as text box or a label dont forget to put its type. and for the "For " statements u got to declare the "I".

here is the corrected code. As for what u wanted., just draw using the present shapes in VB make them invisible and then in ur code just say like circle. Visible every time the user gets it wrong


Option Explicit

Dim choice1(0 To 4) As String
Dim Word As String
Dim Letter As String
Dim counter As Integer

Private Sub cmdGuess_Click()
Dim i As Integer
For i = 1 To Len(Word)
Letter = Mid(Word, i, 1)
Call Check
Next i
lblPicked.Caption = lblPicked.Caption & txtLetter.Text & ","
If counter = Len(Word) Then
MsgBox "You guessed all the letters"
End If
End Sub

Private Sub Check()
If Letter = txtLetter.Text Then
MsgBox Letter & " " & "is in the word"
lblRight.Caption = lblRight.Caption & txtLetter & ","
counter = counter + 1
End If
End Sub

Private Sub Form_Load()
choice1(0) = "cat"
choice1(1) = "dog"
choice1(2) = "mouse"
choice1(3) = "rat"
choice1(4) = "toronto"
Randomize
Word = choice1(Int(Rnd * 5)) 'Randomizes
counter = 0
If Word = "cat" Then
lblCat.Caption = "Animal"
lblLetters.Caption = "3 Letters"
End If
If Word = "dog" Then
lblCat.Caption = "Animal"
lblLetters.Caption = "3 Letters"
End If
If Word = "mouse" Then
lblCat.Caption = "Animal"
lblLetters.Caption = "5 Letters"
End If
If Word = "rat" Then
lblCat.Caption = "Animal"
lblLetters.Caption = "3 Letters"
End If
If Word = "toronto" Then
lblCat.Caption = "Place"
lblLetters.Caption = "7 Letters"
End If
End Sub
G.I._Jane




PostPosted: Mon Feb 23, 2004 1:17 pm   Post subject: (No subject)

you don't know how to work hang man Shocked

well I don't either
Acid




PostPosted: Tue Feb 24, 2004 11:01 am   Post subject: (No subject)

what do the Len and Mid commands do?
rdrake




PostPosted: Wed Feb 25, 2004 12:16 pm   Post subject: (No subject)

The Len() command finds the length of the string. The Mid() command returns only a specified number of characters in a string.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: