# Can anyone help me to find what is going wrong?

Posted by Rice41 on April 05, 1998 at 04:27:20:

Dear all,
I wrote a text box to get the string, but it goes strange because if I type
in "12345" the debug.print shows I only input "1234" which the last charater is mmissed
Can anyone tell me what wrong with my code. Thanks

Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim n As Single
Dim m As Integer
CheckString KeyAscii
Select Case KeyAscii
Case Is = 107 Or 75
SendKeys "{tab}"
n = CSng(Val(Text2))
n = n * 1000
Case Is = 109
SendKeys "{tab}"
n = CSng(Val(Text2))
n = n / 1000
Case Is = 77
SendKeys "{tab}"
n = CSng(Val(Text2))
n = n * 1000000
Case Is = 45
m = Len(Text2)
If m > 1 Then
MsgBox "Invalid input, please submit again"
End If
n = CSng(Val(Text2))
Case Else
n = CSng(Val(Text2))
End Select
End Sub

Function CheckString(X As Integer) As Integer
Dim strValid As String
strValid = "0123456789.-kKnNmM"
If X > 44 And X < 127 Then
If InStr(strValid, Chr(X)) = 0 Then
X = 0
End If
Else
X = 0
End If
End Function

Follow Ups:

- KeyPress 事件本来就就这样 小吴 19:30:11 4/05/98 (0)