2d array q

# Thread: 2d array q

1. Junior Member
Join Date
Dec 1969
Posts
3

## 2d array q

hey all- long q-<BR><BR>got txt file w/11 csv entries & N lines- each column is either 20,40,60,80, or 100(want to count # of 20&#039;s...100&#039;s for each column)<BR><BR>import data ok- but want to insert into array & get results-<BR><BR>csv format:<BR>"20","20"...(total 11 cols)<BR>"40","40"...<BR><BR>so above q1 would have 2vals- 20 & 40<BR><BR>any idea how to proceed?<BR><BR>btw- heres my 2d array script:<BR>response.write count &#039; count is the total # of lines in txt file<BR>dim votes()<BR>redim votes(count,11) &#039;resize to get 2d<BR>response.write "votes" & Ubound(votes) &#039;check that its right (works so far)<BR><BR>ideas?<BR><BR>owlsey@yahoo.com

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: 2d array q

Read each line in by the FSO, split it into a 1d array per line, and then you&#039;ll have to do it like so:<BR><BR>For i = 0 To UBound(votes)<BR> votes(i,0) = splittedArray(0)<BR> ...<BR> votes(i,11) = splittedArray(11)<BR>Next

3. Junior Member
Join Date
Dec 1969
Posts
3

## RE: 2d array q

ok- so to make it dynamic-<BR><BR><BR>dim countarr<BR>For i = 0 To UBound(votes)<BR>votes(i,0) = splittedArray(countarr)<BR>countarr = countarr++<BR>next<BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Don't make it so hard...

&#060;%<BR>Dim arr()<BR>ReDim arr(1000) &#039; arbitrary size<BR><BR>count = -1<BR>Do Until inFile.atEndOfStream<BR>&nbsp; &nbsp; count = count + 1<BR>&nbsp; &nbsp; &#039; if not enough room in array, make it bigger<BR>&nbsp; &nbsp; If count &#062; UBound(arr) Then ReDim Preserve arr(count+100)<BR>&nbsp; &nbsp; arr(count) = Split( inFile.ReadLine, "," )<BR>Loop<BR><BR>&#039; if you want, resize array to exact size:<BR>ReDim Preserve arr(count)<BR><BR>%&#062;<BR><BR>Now you can reference elements of your "2D" array thus:<BR><BR>&#060;%<BR>cell = arr( row )( column )<BR>%&#062;<BR><BR>Note the double pair of parentheses. That&#039;s because what you *actually* have is an Array *OF* Arrays! <BR><BR>But it&#039;s a lot faster to do it this way then use a true 2D array, so why not try it?<BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•