Results 1 to 4 of 4

Thread: [RESOLVED] Simple way to remove blank data from start of textbox?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    168

    Resolved [RESOLVED] Simple way to remove blank data from start of textbox?

    I have an application where the user writes data into a textbox. The first line in the text should contain character Title information. When saving the file, I want to ensure that the beginning of the file contain character data, and not blanks, vbCrLf, etc. I want to remove all data(including vbCrLf, etc) until some valid character data occurs.
    I started writing something and then hit the wall, so to speak. This seems to be more complicated than I thought it would be. Anybody have some ideas on how to identify what is non-character data?

  2. #2
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Re: Simple way to remove blank data from start of textbox?

    Have you tried to use Trim() function?
    I'm still on the path of learning....

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Simple way to remove blank data from start of textbox?

    Trim or LTrim() will delete blanks but not special chars.

    There are many ways to do this, one is searching for the first char higher than 32 in the asccii code list, then removing all chars at left, example:
    Code:
    Private Function RemoveInvalidChars(ByRef pStr As String) As String
    Dim i As Long, lLastInvalidChar As Long
        
        If LenB(pStr) = 0 Then Exit Function
        
        For i = 1 To Len(pStr)
            If Asc(Mid(pStr, i, 1)) > 32 Then
                lLastInvalidChar = i - 1
                Exit For
            End If
        Next
        
        RemoveInvalidChars = Right(pStr, Len(pStr) - lLastInvalidChar)
    End Function
    Usage:
    Code:
        Text1.Text = RemoveInvalidChars(Text1.Text)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    168

    Re: Simple way to remove blank data from start of textbox?

    Hello. Thanks for the replies. The Trim function results in a string with Len > 0 and displays in debug mode as "". Very confusing to me.
    JCIS-I think you've got it. That is exactly what I wanted to see. Thank you very much.
    I have to assume that all language keyboards have no characters < 33(b).

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