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 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
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
"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
"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
"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
"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
Of course, to be clearer, it would be better to just use vbCr and be
done with it.
Of course, to be clearer, it would be better to just use vbCr and be
done with it.
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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |