Results 1 to 4 of 4

Thread: Split Function Gives Weird Results Sometimes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    448

    Split Function Gives Weird Results Sometimes

    Hi.

    I have a section of code that is intended to split a text file's contents into separate lines that go into an array. Each line should then be easily read from the array:

    Code:
     ProjectText_str = Input(FileLen(Filename), #2)   ' Get all of the characters in the file.
    
    ProjectTextAsArray = Split(ProjectText_str, vbLf, -1, 1)
    
    For LineNum = 0 To UBound(ProjectTextAsArray)
    .
    .
    .
    I have tried different delimiters...vbCr returns "1" when their are 199 lines of text, vbCrLf returns "1" as well, and vbLf works most of the time, but sometimes returns something ridiculously huge, like "30777", again, when there are only 199 lines of text in the file.

    What am I doing wrong? Any insight would be great!
    Last edited by treddie; Jul 28th, 2014 at 04:24 PM. Reason: forgot to include code

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Split Function Gives Weird Results Sometimes

    Instead of using 1 as your last parameter use vbBinaryCompare instead

    Split(ProjectText_str, vbCrLf, -1, vbBinaryCompare)


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    448

    Re: Split Function Gives Weird Results Sometimes

    I have tried that but get the same result..."30777".

    Here is the text file:
    0
    0
    0

    0
    0
    0


    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0

    0
    0
    0




    [ProjectNotes]
    Start Note(1,1)

    End Note(1,1)
    Start Note(1,2)

    End Note(1,2)
    Start Note(1,3)

    End Note(1,3)
    Start Note(1,4)

    End Note(1,4)
    Start Note(1,5)

    End Note(1,5)
    Start Note(2,1)
    Front face of Lock Release Panel.
    End Note(2,1)
    Start Note(2,2)
    Front face of waldos.
    End Note(2,2)
    Start Note(2,3)

    End Note(2,3)
    Start Note(2,4)

    End Note(2,4)
    Start Note(2,5)

    End Note(2,5)
    [EndProjectNotes]


  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    448

    Re: Split Function Gives Weird Results Sometimes

    Hold off...Sorry to bother you. The returned value 30777 IS correct. It's been a while since I worked on this program, but the short 199 lines of text is what came back when I printed out the contents of (ProjectText_str). It got truncated for some reason, but the file itself is 30777 lines long. So all is well in that respect. The problem is a file subscript out of range issue that I am tracking down.

    I'll catch the sucker.

    Sorry to waste your time.

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