View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] gw.boswell@gmail.com is offline
external usenet poster
 
Posts: 16
Default Reading Text file into an array

On Apr 18, 1:25 pm, "RB Smissaert"
wrote:
Get the file into a string variable with something like this:

Function OpenTextFileToString(strFile As String) As String

Dim hFile As Long

'obtain file handle, open file
'and load into a string buffer
hFile = FreeFile

Open strFile For Input As #hFile

OpenTextFileToString = Input$(LOF(hFile), hFile)

Close #hFile

End Function

Then you can do something like this:

Sub test()

Dim strString As String
Dim arr

strString = OpenTextFileToString("C:\test.txt")

arr = Split(strString, vbCrLf)

End Sub

Replace the vbCrLf with whatever your delimiter is.

RBS

wrote in message

ups.com...



On Apr 18, 11:52 am, "RB Smissaert"
wrote:
Read your whole text file and put it in a string variable.
Then split the string with the Split function of whatever
delimiter you choose.


RBS


wrote in message


groups.com...


I want to read an ASCII text file that contains variable length lines
into an array. I can read the file a line at a time or a character at
a time but what I really need is to read the text between delimiters
as a unit. Is there an end of line marker (similar to the EOF
marker)? How do I capture the information between delimiters?


TIA
Garry- Hide quoted text -


- Show quoted text -


I'll give that a shot. To load the array how do I locate the end of
the string in which I have placed the file info?- Hide quoted text -


- Show quoted text -


Excellent. I used the tab (Chr(9)) which is the delimiter for this
ASCII file and it worked great. Thanks for the good advice.