Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard events!!

Status
Not open for further replies.

DimMeAsNewbie

Technical User
Mar 17, 2007
20
GB
Does the code below make any sense? I am trying to have a programme that compares the key pressed by user and a character in a word
(The words are stored in a txt.file and i can connect to the file and read through the words.)


Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
input = ChrW(Val(e.KeyChar))
For i = 0 To l - 1
If input = word(i) Then
ostr(i * 2) = word(i)
found = 1
End If
 
So, you press a key, and then you want to analyze the pressed key, and see if it is in a text file? (e.g. I press "G", and the .txt file contains "NADA", therefore no "G", and nothing happens)

Read the file in as a stream, and store it in a string variable (this should be an instance variable). When the KeyPress event is fired, use a .contains( x, y ) on the instance variable holding the text file.
 
so this is a predictive text kind of a thing?

store your dictionary of words in a DataTable in a DataSet.

you can then use the DataTable.Select() and the like operator to get a list of the words that match your criteria.


mr s. <;)

 
So, you press a key, and then you want to analyze the pressed key, and see if it is in a text file? (e.g. I press "G", and the .txt file contains "NADA", therefore no "G", and nothing happens)"

Yes thekl0wn, this is a hangman game and when a letter is pressed it should show in a label on the form and for instance if "G" is pressed and it's part of random letter "Grade" it should apear in the label as G_ _ _ _ , if wrong apear somewhere on the form.
The code is just an extract from my full code
 
NB

I can read into the file, lines and letters already. I'm stuck where the pressedkey compares with the letter from the random word.

Thank you
 
I would use InStr as that will give you the position as well and you could use that to set it to the correct label.

-I hate Microsoft!
-Forever and always forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top