Results 1 to 3 of 3

Thread: Help with Input boxes!?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    5

    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

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    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

    Quote 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
  •  



Click Here to Expand Forum to Full Width