how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
Go Back  Xtreme Visual Basic Talk > > > how to prevent users typing in random letters in a text box-Scrabble Game


Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2011, 03:19 PM
ahmedgulaid1 ahmedgulaid1 is offline
Newcomer
 
Join Date: May 2011
Posts: 1
Default how to prevent users typing in random letters in a text box-Scrabble Game


I have created a scrabble game that generates random letters. For the user to type in a word using the random letters they have to type it in a text box.

I want my program to prevent users from typing in letters that are not provided in the text box and to allow them to type in the random letters that are provided.

any help will be helpful
thanx in advance
Reply With Quote
  #2  
Old 05-08-2011, 08:18 AM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default

This shouldn't be too hard... put your random numbers into a string array. and use "InStr" (In String) to see if the letter being offered is the one of the valid random letters.

Last edited by CodeCruncher; 05-08-2011 at 10:42 AM.
Reply With Quote
  #3  
Old 05-08-2011, 10:39 AM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default

I spent a few hours trying to work out how I would write this game...

I was going down this track.

Code:
    Dim bytRandom As Byte = 0
    Dim strRandom(7) As String
    Dim A_bytCountMe As Byte
    Dim B_bytCountMe As Byte
    Dim C_bytCountMe As Byte
    Dim D_bytCountMe As Byte

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim rndLettter As New Random

        Do Until strRandom(7) <> Nothing
            Dim charRandom As Char = Chr(rndLettter.Next(65, 90)) 'Create a random capital letter - A to Z inclusive.
            Select Case charRandom
                Case Is = "A"
                    If A_bytCountMe < 2 Then
                        strRandom(bytRandom) = charRandom
                        A_bytCountMe += 1
                        bytRandom += 1
                    End If
                Case Is = "B"
                    If B_bytCountMe < 2 Then
                        strRandom(bytRandom) = charRandom
                        B_bytCountMe += 1
                        bytRandom += 1
                    End If
                Case Is = "C"
                    If C_bytCountMe < 2 Then
                        strRandom(bytRandom) = charRandom
                        C_bytCountMe += 1
                        bytRandom += 1
                    End If

.....
If strRandom.Contains("A") = True Then

....
End If
Being that you only get a certain amount of each letter i.e 5 A's, 2 Z's etc. I was trying to limit the array to a max of 2 of each letter, then it dawned on me I was looking at it the wrong way.

The better way to do it is start by assigning a number to each of the letters that come with the game... No 1 to 5 are A, 6 to 8 are B etc.

Say there are 100 pieces in total (no idea just a guess). Create a random number from 1 to 100 and then match the number to the letter. Take those allocated numbers out of the random selection so they cant be selected again, that way it will work like the real game.

Last edited by CodeCruncher; 05-08-2011 at 10:45 AM.
Reply With Quote
  #4  
Old 05-13-2011, 09:15 AM
AtmaWeapon's Avatar
AtmaWeaponhow to prevent users typing in random letters in a text box-Scrabble Game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You know what's a better choice and looks a heck of a lot better? Show the user 7 buttons and let them click the buttons to enter a letter. Disable buttons when they're clicked.

There's a much less tedious way to restrict a text box like this, but arbitrary restriction of typing in text boxes tends to lead to a frustrating user experience. I can take a hack at the text box solution but I don't want to do so since having 7 clickable letters is a much better experience for the user.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 05-13-2011, 08:15 PM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default

Sounds like a cool way to do it maybe even make the letter appear on the button text instead of using any text boxes.. and a seperate button to submit the turn / refresh the used letters once the turn is over.

Really the quantity of letters in the game are set (your not adding new ones) so there really isn't a need for any text boxes.

The order the buttons are pressed could determine the displayed order...

I almost feel like writting this game myself lol but have way too much to do.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
 
how to prevent users typing in random letters in a text box-Scrabble Game
how to prevent users typing in random letters in a text box-Scrabble Game
 
-->