I have to write a routine to import a Tab delimited file into an array. Nothing I do seems to work easily without the following work-around.
Doing it this way works, but is s-l-o-w. Can anyone speed up this code? BTW, the client cannot change to a comma delimited format, which would be real easy for us.Code:Line Input #iInHandle, sLine iCtr2 = 1 ' "sTemp" hold data as we read it in sTemp = "" ' parse the line to the array elements - look for "iDelimitChar" which ' is the delimiter between fields For iCtr = 1 To Len(sLine) ' look for delimiter If Mid(sLine, iCtr, 1) <> Chr(iDelimitChar) Then ' it wasn't a delimiter char, so add it to "sTemp" sTemp = sTemp & Mid(sLine, iCtr, 1) Else ' it was a delimiter, so we are thru with this element - load the ' array element with the value of "sTemp" sArray(iCtr2) = sTemp ' re-initialize "sTemp" and increment the element counter ("iCtr2") sTemp = "" iCtr2 = iCtr2 + 1 End If Next iCtr ' Once we fall out of the loop, it's because we have reached the end ' of the line. Since there is no trailing delimiter, then everything in ' "sTemp" will go into the last array used element sArray(iCtr2) = sTemp
Thanks.




Reply With Quote