You cannot check the value in the keypress. It will try to validate everynumber so you will never be able to put in 255. You can use a regular expression and either a ErrorProvider control (For a windows app) or a RegularExpression Validator Control( for a web app )
I am going to take a guess and say that you are trying to match and IP address. This regular expression will match an ip address that is like :
10.55.255.255
Of course the numbers between the periods can be anything bewtween 0 and 255. Here it is
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
to use it you need to use the RegEx object.
'Your regex object
Dim oRegEx As Regex
Dim x As Boolean
'The parameters are
oRegEx = New Regex("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
'This checks a specific text box
x = oRegEx.IsMatch(Me.txtAmount.Text)
If x = False Then
'This sets the error provider
ErrorProvider1.SetError(txtAmount, "IP must be in correct format 255.255.255.255"
Else
'This clears it for the textbox
ErrorProvider1.SetError(txtAmount, ""

End If
One last thing. You need to use the following imports statement in your code
Imports System.Text.RegularExpressions
Hope this helps. Let me know if you have questions.
DotNetDoc
M.C.S.D.
---------------------------------------
Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein