Re: Entry exclusion logic
u can use the ascii table, where each each character has a ascii code
in ascii table the no from 65 to 90 is for Capital alphabets, to stop them from entry we do it like
Code:
If Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90 Then
e.Handled = True
End If
Re: Entry exclusion logic
u may also use the Key Code constants , like this to disable the space
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Keys.Space Then
e.Handled = True
End If
End Sub
here are the Key code Constants
Re: Entry exclusion logic
Thank you for your reply, however we are not using the ASCII tables in class yet so I don't believe it's the solution I should be using. Although I could, we are only graded on if the app functions as it's supposed to (homework anyway) not how it's coded. I have though about also excluding all of the characters individually (ie ":", ";" or the keys.* that you outlined, etc) but that seems cumbersome and inefficient and probably the worst way to code it (although it should work).
Re: Entry exclusion logic
I guess I'll have to manually exlude each special character. Seems wasteful.
Re: Entry exclusion logic
Seems easyer to make a collection of strings, with each letter in upper case.
And then make a validation of the characters entered in the textbox.
Re: Entry exclusion logic
u can also use the isLetter ,isDigit functions.
Code:
If Not Char.IsLetter(e.KeyChar) Then
e.Handled = True
End If
Re: Entry exclusion logic
simply can write like this to allow only letters
Code:
If (Char.IsLetter(e.KeyChar) = False) Then
e.Handled = True
End If
Code:
e.Handled = Not Char.IsLetter(e.KeyChar)
Re: Entry exclusion logic
[QUOTE=aniskhan]simply can write like this to allow only letters
Code:
If (Char.IsLetter(e.KeyChar) = False) Then
e.Handled = True
End If
Hey, that worked! Very cool. This textbook sucks :thumbd: