473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Look For CR in Text Data

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(txtComment.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(txtComment.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(txtComment.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
Jul 17 '05 #1
9 6801
I found that:

Sub txtComment_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
'Issue message
MsgBox "Enter is not allowed in message text"
KeyAscii = 0
End If

End Sub

works.

Sorry about asking. I hope this helps someone else.

Stephen Saunders

"Stephen Saunders" <kd****@earthlink.net> wrote in message
news:6p***************@newsread3.news.atl.earthlin k.net...
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(txtComment.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(txtComment.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(txtComment.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

Jul 17 '05 #2
I found that:

Sub txtComment_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
'Issue message
MsgBox "Enter is not allowed in message text"
KeyAscii = 0
End If

End Sub

works.

Sorry about asking. I hope this helps someone else.

Stephen Saunders

"Stephen Saunders" <kd****@earthlink.net> wrote in message
news:6p***************@newsread3.news.atl.earthlin k.net...
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(txtComment.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(txtComment.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(txtComment.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

Jul 17 '05 #3

"Stephen Saunders" <kd****@earthlink.net> wrote in message
news:6p***************@newsread3.news.atl.earthlin k.net...
Hey Folks,
This doesn't find the CR because CStr(13) equals a two character string
("13")


Try this Steve..

Put a text box and label on a form and a command button:

Private Sub Command1_Click()
Dim t$
Dim x
t$ = Text1.Text

x = InStr(t$, Chr$(13))
If x > 0 Then
Label1.Caption = "CR found at pos " & x
Else
Label1.Caption = "No CR found"
End If

End Sub
Jul 17 '05 #4

"Stephen Saunders" <kd****@earthlink.net> wrote in message
news:6p***************@newsread3.news.atl.earthlin k.net...
Hey Folks,
This doesn't find the CR because CStr(13) equals a two character string
("13")


Try this Steve..

Put a text box and label on a form and a command button:

Private Sub Command1_Click()
Dim t$
Dim x
t$ = Text1.Text

x = InStr(t$, Chr$(13))
If x > 0 Then
Label1.Caption = "CR found at pos " & x
Else
Label1.Caption = "No CR found"
End If

End Sub
Jul 17 '05 #5

"Stephen Saunders" <kd****@earthlink.net> skrev i en meddelelse
news:6p***************@newsread3.news.atl.earthlin k.net...
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(txtComment.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


CStr(13) is NOT a CR, CStr(13) is "13" ! CHR(13) is a CR ! ;-)

And what's wrong with

IF instr(1, txtComment.Text, vbCR) > 0 the
MsgBox "Comment cannot contain the enter character"

txtComment.Text = Replace(txtComment.Text, vbCR, "")
End IF
--
/\ preben nielsen
\/\ pr**@post.tele.dk
Jul 17 '05 #6

"Stephen Saunders" <kd****@earthlink.net> skrev i en meddelelse
news:6p***************@newsread3.news.atl.earthlin k.net...
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(txtComment.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


CStr(13) is NOT a CR, CStr(13) is "13" ! CHR(13) is a CR ! ;-)

And what's wrong with

IF instr(1, txtComment.Text, vbCR) > 0 the
MsgBox "Comment cannot contain the enter character"

txtComment.Text = Replace(txtComment.Text, vbCR, "")
End IF
--
/\ preben nielsen
\/\ pr**@post.tele.dk
Jul 17 '05 #7
Of course, to be clearer, it would be better to just use vbCr and be
done with it.

Jul 17 '05 #8
Of course, to be clearer, it would be better to just use vbCr and be
done with it.

Jul 17 '05 #9
Here's a solution

dim i as integer

private sub Command1_Click()

open "orig.txt" for input as #1
'This would be the file you are trying to find the CR

while not eof(1)
a = input$(1, 1)
i = i + 1

if a$ = chr(13) then
MsgBox (msg = "CR Found at" & i & "Char")
'This will give you the number of char's reached until CR was found
end if

wend
end sub

I could get more detailed but this should be enough for you. If not let me know.
Oct 25 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Simeon Nevel | last post by:
As a personal exercise, I'm trying to create a call tracking DB for my own use at work. Here's an abbreviated version of the database layout: Company: CompanyID - Primary Key (Text Length...
2
by: tshad | last post by:
I have a screen that is displaying an asp:textbox that has about 20 lines of text with line feeds that I read out of my Database. This displays fine as a multiline textbox. It doesn't as a...
16
by: John Rivers | last post by:
http://www.15seconds.com/Issue/030812.htm?voteresult=1 poor guy worked his heart out, just to make a page control and then they published it ha ha ha ha ha to "help" others
14
by: Joe | last post by:
Hello All: I am trying to dynamically populate a web page with literal content and controls (textboxes and checkboxes (and eventually two buttons - the buttons do not appear in the code yet). I...
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
5
by: Takeadoe | last post by:
Gang - I'm generating date and time variables from scanned forms. Currently, the date and time values are as follows: 06/26/2006 and 11:30 AM. I've written VBA code to combine them into a...
1
by: teddymeu | last post by:
hi guys I posted the other day regarding a solution i needed to design, im new to development an asp,net and built a local post office search tool using asp.net 2. vb in visual studio, using an...
13
by: pvong | last post by:
VB.Net I'm pulling Data from a DB and creating a letter by filling the Labels. It works perfectly, but if Addr2 and Addr3 are blank, it leaves a Blank space in that area. Is there a way to...
9
by: MNNovice | last post by:
Look up Text Box Vs Combo Box tblOrg has these fields OrgID PK OrgNo Text OrgDescr Text I would like to see the OrgNo get displayed in two other tables: tblExpense...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.