Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i need to split a file into a 2-dimensional array

Status
Not open for further replies.

bfellows

Technical User
Sep 17, 2002
10
US
I have several different csv price grids for my company's product. For example, the files might look something like this:

0,6,12,18,24,30
12,100,120,140,160,180
24,200,220,240,260,280
36,300,320,340,360,380

Despite concern that I may muddy the waters a bit by explaining it, the top row and left column are measurements and the other numbers are prices.

Anyhow, I want to split this thing up and put it into a 2-dimensional array so that, for example:

"arr_grid(0,0)" evaluates to "0"
"arr_grid(1,3)" evaluates to "300"
"arr_grid(3,2)" evaluates to "240"

From there I intend on using VBA's built-in ubound function to determine the array's size.

I already have this working on our company's fixed-size csv files, but I want to support dynamic-sized csvs for ease of maintenance and to future proof it a bit.

Any suggestions?
 
Using the split function, for sure.

Open your file for reading(i assume you know this much)

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile("c:\testfile.txt", ForReading, False)
Do While a.AtEndOfLine <> True

varArray = Split(fso.ReadLine,",")
For y = 0 to Ubound(varArray)
myAray(x,y) = varArray(y)
Next y

x = x + 1
Loop


...something like this, my syntax and logic may be off here
& there, but I hope you get the idea.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top