Tuesday, March 1, 2011

Vb6: Separating Tab Delimited Text

I have a file with several thousand rows and several columns separated with tabs What I'd like to do is loop through each individually, Drop the columns into an array so that I can place them in another application individually, then move onto the next line. Unfortunately I got about as far as this:

Open mytextfile.txt For Input As #FileHandle
 Do While Not EOF(FileHandle)
 Line Input #FileHandle, IndividualLine
 StringToBreakup = IndividualLine
Loop

So how would I go about breaking individual line up into an array

From stackoverflow
  • Use the split command

    Dim StringArray as Variant
    
    Open mytextfile.txt For Input As #FileHandle
     Do While Not EOF(FileHandle)
     Line Input #FileHandle, IndividualLine
     StringToBreakup = IndividualLine
    
     StringArray = Split(StringToBreakup, CHR(9)) 
    
     Process array here...
    
    Loop
    
  • Dim str() as String
    
    Open mytextfile.txt For Input As #FileHandle
        Do While Not EOF(FileHandle)
        Line Input #FileHandle, IndividualLine
        str = Split(IndividualLine, vbTab)
        Debug.Print str(0)  'First array element
    Loop
    

    To clarify: I would avoid the use of Variants and use vbTab.

0 comments:

Post a Comment