|
-
Nov 25th, 2000, 11:57 PM
#1
Thread Starter
Lively Member
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.
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
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.
Thanks.
-
Nov 26th, 2000, 02:35 AM
#2
Addicted Member
Using the Split() function would perhaps be better for your purpose. Like this:
Code:
-------------------------------------
Dim strFileName As String
Dim intFileNum As Integer
Dim strContent As String
Dim strArray() As String
intFileNum = FreeFile
strFileName = "PathAndFileName"
Open strFileName For Binary As #intFileNum
strContent = String(LOF(intFileNum), 0)
Get #intFileNum, , strContent
Close intFileNum
strArray = Split(strContent, vbTab)
------------------------------------
-
Nov 26th, 2000, 12:09 PM
#3
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|