LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default limit to possible array size?

I'm working on code that reads in a text file line by line, splits the data
by the delimiter and puts the string into an array, collects the fields i
want (i don't want them all) into another array, and writes the data i want
into a spreadsheet. The text file has 1134 fields. At some point, however,
the code bombs with a "subscript out of range error" on the text string
array. While trying to figure out what was going on, I found out that the
upper limit of the text string array was 1050 - well short of the 1134 fields
that are in the text file. Is there a size limit to arrays or am i having
some other kind of problem? I'll be the first to admit that i'm pretty much
winging it here.

The part of the code where i'm having difficulty is below.


' strArray contains the line of text from the text file (ubound = 1050)
' varArray has a list of the fields i want to import (taken from another
source)
' partArray is where the fields/data i want from strArray are stored

strSourceFile = "C:\Data.txt"
lngInputFile = FreeFile
Open strSourceFile For Input As lngInputFile
iRowCount = 1
While Not EOF(lngInputFile)
Line Input #lngInputFile, strInText
strArray = Split(strInText, "~")
ReDim partArray(1)

' i want the first 130 fields and a subset of the remaining fields in the
data file.

For i = 1 To 130
partArray(i - 1) = strArray(i - 1)
ReDim Preserve partArray(UBound(partArray) + 1)
Next i
ReDim Preserve partArray(UBound(partArray) + 1)
For i = 1 To UBound(varArray)
fieldNum = varArray(i)
partArray(i + 130) = strArray(fieldNum + 129) ''WHERE THE ERROR OCCURS
ReDim Preserve partArray(UBound(partArray) + 1)
Next i
Worksheets("Sheet2").Cells(iRowCount, 1).Resize(1, UBound(partArray, 1)
+ 1).Value = partArray
Wend
Close lngInputFile


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit the size of a cell Joël Excel Discussion (Misc queries) 2 September 22nd 09 01:36 PM
Is there an array size limit for MMULT or MINVERSE in excel 2007? jimr315 Excel Worksheet Functions 4 February 7th 07 10:48 PM
Cell size? Or size limit for Text data type? CClem Excel Discussion (Misc queries) 0 April 21st 06 04:09 PM
How to find out the size of a variable-size array ? Adrian[_7_] Excel Programming 1 July 6th 04 09:12 AM


All times are GMT +1. The time now is 10:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"