CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Location
    Colorado
    Posts
    105

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    516

    Re: Check string for Carriage Return

    Quote 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)

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    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)

  4. #4
    Join Date
    Mar 2002
    Location
    Colorado
    Posts
    105

    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
  •  





Click Here to Expand Forum to Full Width

Featured