|
-
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
-
Oct 28th, 2009, 01:00 PM
#2
Re: Help with Input boxes!?
The inputbox is available as it is and won't allow customization to that level.
You can design your own form similar to an inputbox and set the textbox length, and whatever other features you need. It should be easy to do that.
-
Oct 28th, 2009, 01:22 PM
#3
Re: Help with Input boxes!?
I've always used MaskedTextBoxes. They allow you to set a "Mask" that will do what you want.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
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
|