|
-
Oct 28th, 2009, 12:54 PM
#1
Thread Starter
New Member
Help with Input boxes!?
Hey guys... I'm coding a hangman game for a class.. and it is set up so that an input box comes up to prompt the user for a letter. Is there any way to set an input box length to only accept letters, backspace, and will not accept a length longer than 1? This is what i have so far.
**************************************************
//This is the segment of code i would like to edit so that the length will only accept 1 character... is this possible. If not, how can i set it so that when a number is entered or an incorrect amount of characters is entered, it will not could this as an incorrect guess? //
'get a letter from player 2, convert to uppercase
letter = InputBox("Enter a letter:", _
"Letter", "", 820, 590).ToUpper
*************************************************
//I threw this segment following after just so you can see the logic. //
' verify that player 2 entered a letter
' and that the game is not over
Do While letter <> String.Empty AndAlso isGameOver = False
' search the word for the letter
For indexNum As Integer = 0 To length - 1
'if the letter appears in the word, then
' replace the dash in the wordLabel and
' indicate that a replacement was made
If word.Substring(indexNum, 1) = letter Then
Mid(wordLabel.Text, indexNum + 1) = letter
isDashReplaced = True
End If
Next indexNum
' determine whether a dash was replaced
If isDashReplaced = True Then
' if the word does not contain any dashes,
' the game is over because player 2
' guessed the word; otherwise, reset the
' isDashReplaced variable for the next search
If wordLabel.Text.Contains("-") = False Then
isGameOver = True
MessageBox.Show("Great guessing!", _
"Game Over", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Else
isDashReplaced = False
End If
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
|