-
July 17th, 2006, 05:43 PM
#1
Check string for Carriage Return
Hi all,
I want to read in the value of a string for comparison purposes that has been passed from an excel(cell) through VBA. When the value is read into a string variable, some of them contain, carriage return characters(A square box). how can I determine the ascii character value of the carriage return? I attempted to read the chr(13) value, but this did not do want i needed.
Here is what i have so far:
Code:
Dim i As Integer
Dim sectionHolder As String
i = 1
Do Until i = Len(sectionName) + 1
If Mid(sectionName, i, 1) <> Chr(13) Then
sectionHolder = sectionHolder + Mid(sectionName, i, 1)
i = i + 1
Else
Exit Do
End If
Loop
-
July 17th, 2006, 05:54 PM
#2
Re: Check string for Carriage Return
Originally Posted by lbargers
Hi all,
I want to read in the value of a string for comparison purposes that has been passed from an excel(cell) through VBA. When the value is read into a string variable, some of them contain, carriage return characters(A square box). how can I determine the ascii character value of the carriage return? I attempted to read the chr(13) value, but this did not do want i needed.
It could be a line feed instead depending on where you are getting it from. There are two nice VB constants, vbCR and vbLF for carriage return and line feed.
Code:
If Mid(sectionName, i, 1) <> vbCr Then
What do you need to do, just strip them out? If so, the easier way would be to use the Replace function:
Code:
sectionHolder = Replace(sectionName, vbCr, vbNullString)
-
July 18th, 2006, 08:43 AM
#3
Re: Check string for Carriage Return
If in doubt about the character's value, try to find out which one you have:
Code:
for i=1 to len(sectionName)
debug.print asc(mid$(sectionName,i,1));" ";
next
This will soon show you the asc od the end-of-line character(s)
-
July 18th, 2006, 11:43 AM
#4
Re: Check string for Carriage Return
Thanks for the responses. Its working like a charm now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|