Results 1 to 2 of 2

Thread: The final word in the array!? :(

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    10

    Smile The final word in the array!? :(

    This code works fine except it does not pick up the last word at the end of the line. The text file it reads, words are seperated by tabs. When running this code it picks up every word except for the last and chucks it in the array, any ideas to find out how to get the last word placed in the array.

    Thanks, Schoolproject.

    Code:
            Do Until strStudent Is Nothing                          ' this will run through the read line function until it finds the end of the whole file itself
    
                For j = 1 To Len(strStudent)                        ' this will read through the entire line itself
                    ochar = Mid(strStudent, j, 1)                   ' ochar is used as a single character in the file, command mid reads strstudent, j letter and reads one character
                    ostring = ostring + ochar                       ' builds the string by adding characters to ostring
    
                    If ochar = Chr(9) Then                          ' if the program finds a tab
                        ofield = ofield + 1                         ' changes where about the program chucks the data into the array
                        codes(ocount, ofield) = Mid( _
                        ostring, 1, Len(ostring) - 1)               ' chucking the data into the array
                        ostring = ""                                ' setting the ostring back to null
                        MsgBox(codes(ocount, ofield))
                    End If
    
    
                Next j                                              ' next tab in the line
                codes(ocount, 0) = ocount                           ' moves the array so that the program doesn't overwrite the data that was just entered
                ocount = ocount + 1                                 ' goes up by one, by the end of creating the array you will have x amount of rows
                strStudent = objFile1.ReadLine()                    ' reading the file
                ostring = ""                                        ' setting ostring as null
                ofield = 0                                          ' setting ofield as null
    Loop

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: The final word in the array!? :(

    I'm not sure what the implementation requirements are for this code but it would be easier to call String.Split and specify ControlChars.Tab as the delimiter.

    As for the code you have, I would guess that the issue is that you're looking for Tab characters to end a word and the last word in the line doesn't have a Tab character after it. You should probably look for Tabs or line breaks.

Tags for this Thread

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