key combination creates problems

G

Guest

hi,

my alphanumeric only text box reports error, when the combination of TAB,
CAPS LOCK, SHIFT, CONTROL, ENTER keys( any COMBINATION of these keys) are
pressed.

could you please tell me how to avoid the keystrokes(combination of any) and
thus avoid the message?

Regards,
Hari
 
P

Paul G. Tobey [eMVP]

I think you're going to have to tell us a little more: what version of the
..NET CF are you running this with, for example? Where? Device or emulator?
Surely you don't get an error when you just press and release the Control
key. Please be very specific and show the code for the alphanumeric text
box or tell us exactly what control you are using and how it is configured.
I also don't understand what you mean by avoid the keystrokes...

Paul T.
 
G

Guest

hi,
i am working with vs 2003, cf version 1.1, and testing the application in hp
& asus pocket pcs. Yes, I am not getting any error, when any of those keys
is pressed(only one keystroke). But I am talking about the combination of
keys. for example, when the user taps the CONTROL key, it will be in a
pushed down state and next we press the CAPITAL key, an error message is
displayed (combination of CONTROL & CAPITAL keys). The same error message is
displayed when CONTROL+TAB is pressed, and sometimes with CONTROL + SHIFT
also.

What I meant by 'avoid the keystrokes' is, when the user press a particular
key, the corresponding action will be neglected, i.e, if the user is pressing
CONTROL key, no action has to take place.

I will paste the code here:

Private Function IsAlphaNumeric(ByVal Text As String) As Boolean
'returns true if all characters in a string are alphabetical or
numeric
'returns false otherwise or for empty string

Dim sTemp As String
Dim iLen As Integer
Dim iCtr As Integer
Dim sChar As String


sTemp = Text
iLen = Len(sTemp)
If iLen > 0 Then
For iCtr = 1 To iLen
sChar = Mid(sTemp, iCtr, 1)
If Not sChar Like "[0-9A-Za-z]" Then Exit Function
Next
IsAlphaNumeric = True
End If
End Function
---------------------
and uses the function in the key_up event of a text box:

Private Sub txtSample_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtSample.KeyUp
'function call here:
If Not IsAlphaNumeric(txtSample.Text) Then
If e.KeyData = Keys.Back Then
ElseIf e.KeyData = Keys.CapsLock Then
ElseIf e.KeyData = Keys.ControlKey Then
ElseIf e.KeyData = Keys.ShiftKey Then
ElseIf e.KeyData = Keys.Tab Then
Else
MessageBox.Show("Please Enter AlphaNumeric Values", "Invalid
Data", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
txtSample.Text = ""
txtSample.Focus()
End If
End If
End Sub
------------------------------------------------
regards,
hari
 
S

Sergey Bogdanov

The IsAlphaNumeric calls before all your conditions, try this:

Private Function IsAlphaNumeric(ByVal Text As String) As Boolean
Dim sTemp As String
Dim iLen As Integer
Dim iCtr As Integer
Dim sChar As String


sTemp = Text
iLen = Len(sTemp)
If iLen > 0 Then
For iCtr = 1 To iLen
sChar = Mid(sTemp, iCtr, 1)
If Not sChar Like "[0-9A-Za-z]" Then Exit Function
Next
End If
IsAlphaNumeric = True
End Function

Protected Overrides Sub OnKeyUp(ByVal e As
System.Windows.Forms.KeyEventArgs)
If Not IsAlphaNumeric(Text) Then
MessageBox.Show("Please Enter AlphaNumeric Values")
Text = ""
Focus()
End If
End Sub

Best regards,
Sergey Bogdanov

hi,
i am working with vs 2003, cf version 1.1, and testing the application in hp
& asus pocket pcs. Yes, I am not getting any error, when any of those keys
is pressed(only one keystroke). But I am talking about the combination of
keys. for example, when the user taps the CONTROL key, it will be in a
pushed down state and next we press the CAPITAL key, an error message is
displayed (combination of CONTROL & CAPITAL keys). The same error message is
displayed when CONTROL+TAB is pressed, and sometimes with CONTROL + SHIFT
also.

What I meant by 'avoid the keystrokes' is, when the user press a particular
key, the corresponding action will be neglected, i.e, if the user is pressing
CONTROL key, no action has to take place.

I will paste the code here:

Private Function IsAlphaNumeric(ByVal Text As String) As Boolean
'returns true if all characters in a string are alphabetical or
numeric
'returns false otherwise or for empty string

Dim sTemp As String
Dim iLen As Integer
Dim iCtr As Integer
Dim sChar As String


sTemp = Text
iLen = Len(sTemp)
If iLen > 0 Then
For iCtr = 1 To iLen
sChar = Mid(sTemp, iCtr, 1)
If Not sChar Like "[0-9A-Za-z]" Then Exit Function
Next
IsAlphaNumeric = True
End If
End Function
---------------------
and uses the function in the key_up event of a text box:

Private Sub txtSample_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtSample.KeyUp
'function call here:
If Not IsAlphaNumeric(txtSample.Text) Then
If e.KeyData = Keys.Back Then
ElseIf e.KeyData = Keys.CapsLock Then
ElseIf e.KeyData = Keys.ControlKey Then
ElseIf e.KeyData = Keys.ShiftKey Then
ElseIf e.KeyData = Keys.Tab Then
Else
MessageBox.Show("Please Enter AlphaNumeric Values", "Invalid
Data", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
txtSample.Text = ""
txtSample.Focus()
End If
End If
End Sub
------------------------------------------------
regards,
hari



:

I think you're going to have to tell us a little more: what version of the
..NET CF are you running this with, for example? Where? Device or emulator?
Surely you don't get an error when you just press and release the Control
key. Please be very specific and show the code for the alphanumeric text
box or tell us exactly what control you are using and how it is configured.
I also don't understand what you mean by avoid the keystrokes...

Paul T.
 
G

Guest

Thanks. now the program stopped reporting error messages while pressing
CONTROL, SHIFT, CAPS LOCK, TAB keys and their combinations. Only CONTROL+TAB
reports errors. that case can be neglected. (this was possible, only when the
following code was also used in the key up event)

But the Protected Overrides Sub OnKeyUp is never called while data is
entered. so again i have to stick on to the following code:

If Not IsAlphaNumeric(txtSample.Text) Then


Sergey Bogdanov said:
The IsAlphaNumeric calls before all your conditions, try this:

Private Function IsAlphaNumeric(ByVal Text As String) As Boolean
Dim sTemp As String
Dim iLen As Integer
Dim iCtr As Integer
Dim sChar As String


sTemp = Text
iLen = Len(sTemp)
If iLen > 0 Then
For iCtr = 1 To iLen
sChar = Mid(sTemp, iCtr, 1)
If Not sChar Like "[0-9A-Za-z]" Then Exit Function
Next
End If
IsAlphaNumeric = True
End Function

Protected Overrides Sub OnKeyUp(ByVal e As
System.Windows.Forms.KeyEventArgs)
If Not IsAlphaNumeric(Text) Then
MessageBox.Show("Please Enter AlphaNumeric Values")
Text = ""
Focus()
End If
End Sub

Best regards,
Sergey Bogdanov

hi,
i am working with vs 2003, cf version 1.1, and testing the application in hp
& asus pocket pcs. Yes, I am not getting any error, when any of those keys
is pressed(only one keystroke). But I am talking about the combination of
keys. for example, when the user taps the CONTROL key, it will be in a
pushed down state and next we press the CAPITAL key, an error message is
displayed (combination of CONTROL & CAPITAL keys). The same error message is
displayed when CONTROL+TAB is pressed, and sometimes with CONTROL + SHIFT
also.

What I meant by 'avoid the keystrokes' is, when the user press a particular
key, the corresponding action will be neglected, i.e, if the user is pressing
CONTROL key, no action has to take place.

I will paste the code here:

Private Function IsAlphaNumeric(ByVal Text As String) As Boolean
'returns true if all characters in a string are alphabetical or
numeric
'returns false otherwise or for empty string

Dim sTemp As String
Dim iLen As Integer
Dim iCtr As Integer
Dim sChar As String


sTemp = Text
iLen = Len(sTemp)
If iLen > 0 Then
For iCtr = 1 To iLen
sChar = Mid(sTemp, iCtr, 1)
If Not sChar Like "[0-9A-Za-z]" Then Exit Function
Next
IsAlphaNumeric = True
End If
End Function
---------------------
and uses the function in the key_up event of a text box:

Private Sub txtSample_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtSample.KeyUp
'function call here:
If Not IsAlphaNumeric(txtSample.Text) Then
If e.KeyData = Keys.Back Then
ElseIf e.KeyData = Keys.CapsLock Then
ElseIf e.KeyData = Keys.ControlKey Then
ElseIf e.KeyData = Keys.ShiftKey Then
ElseIf e.KeyData = Keys.Tab Then
Else
MessageBox.Show("Please Enter AlphaNumeric Values", "Invalid
Data", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
txtSample.Text = ""
txtSample.Focus()
End If
End If
End Sub
------------------------------------------------
regards,
hari



:

I think you're going to have to tell us a little more: what version of the
..NET CF are you running this with, for example? Where? Device or emulator?
Surely you don't get an error when you just press and release the Control
key. Please be very specific and show the code for the alphanumeric text
box or tell us exactly what control you are using and how it is configured.
I also don't understand what you mean by avoid the keystrokes...

Paul T.


hi,

my alphanumeric only text box reports error, when the combination of TAB,
CAPS LOCK, SHIFT, CONTROL, ENTER keys( any COMBINATION of these keys) are
pressed.

could you please tell me how to avoid the keystrokes(combination of any)
and
thus avoid the message?

Regards,
Hari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top