Hey Folks,
This one currently has me stumped. I have to check for the existence of a
carriage return (Enter key, hex 0D) in text data. First I tried:
'Check comment to not contain the CR (13) character
For i = 1 To Len(txtComment. Text)
On Error GoTo BogusComment2
If Mid(txtComment. Text, i, 1) = CStr(13) Then
MsgBox "Comment cannot contain the enter character"
'Strip the CR from the comment
txtComment.Text = Left(txtComment .Text, (i - 1)) + _
Right(txtCommen t.Text, (Len(txtComment .Text) - i))
Exit Sub
End If
On Error GoTo 0
Next i
This doesn't find the CR because CStr(13) equals a two character string
("13")
Then I tried:
'Check comment to not contain the CR (13) character
For i = 1 To Len(txtComment. Text)
On Error GoTo BogusComment2
If CInt(Mid(txtCom ment.Text, i, 1)) = 13 Then
MsgBox "Comment cannot contain the enter character"
'Strip the CR from the comment
txtComment.Text = Left(txtComment .Text, (i - 1)) + _
Right(txtCommen t.Text, (Len(txtComment .Text) - i))
Exit Sub
End If
On Error GoTo 0
Next i
This code traps to BogusComment when the first (non CR) character in the
string is checked.
Will using a KeyPress event to fix this?
Stephen Saunders
This one currently has me stumped. I have to check for the existence of a
carriage return (Enter key, hex 0D) in text data. First I tried:
'Check comment to not contain the CR (13) character
For i = 1 To Len(txtComment. Text)
On Error GoTo BogusComment2
If Mid(txtComment. Text, i, 1) = CStr(13) Then
MsgBox "Comment cannot contain the enter character"
'Strip the CR from the comment
txtComment.Text = Left(txtComment .Text, (i - 1)) + _
Right(txtCommen t.Text, (Len(txtComment .Text) - i))
Exit Sub
End If
On Error GoTo 0
Next i
This doesn't find the CR because CStr(13) equals a two character string
("13")
Then I tried:
'Check comment to not contain the CR (13) character
For i = 1 To Len(txtComment. Text)
On Error GoTo BogusComment2
If CInt(Mid(txtCom ment.Text, i, 1)) = 13 Then
MsgBox "Comment cannot contain the enter character"
'Strip the CR from the comment
txtComment.Text = Left(txtComment .Text, (i - 1)) + _
Right(txtCommen t.Text, (Len(txtComment .Text) - i))
Exit Sub
End If
On Error GoTo 0
Next i
This code traps to BogusComment when the first (non CR) character in the
string is checked.
Will using a KeyPress event to fix this?
Stephen Saunders
Comment