View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rachel Rachel is offline
external usenet poster
 
Posts: 113
Default array: subscript out of range

I'm playing around with code to import data from a huge delimited text file.
Since i'm learning as i go, i'm trying to take the code in pieces. Below is
what i have so far.

--------------
Dim strInText As String
Dim strArray() As String
strSourceFile = "C:\ShortTest.txt"
lngInputFile = FreeFile
Open strSourceFile For Input As lngInputFile
iCount = 0
While Not EOF(lngInputFile)
Line Input #lngInputFile, strInText
strArray = Split(strInTest, "~")
Debug.Print Trim(strArray(iCount)) ' [just seeing if the data are
being read]
iCount = iCount + 1
Wend
Close lngInputFile
--------------

I get a "subscript out of range" error on the Debug.Print line. When i move
the cursor over strInText in the Line Input # line, it shows the first line
from the text file as I would expect it to look. But when i move the cursor
over the strInText in the strArray=Split line, it says = Empty. I'm guessing
this is why i get the "subscript out of range" error.

I don't know what could be causing this, but again, i'm learning as i go.
Help!

thanks
rachael