ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using Seek to read csv file (https://www.excelbanter.com/excel-discussion-misc-queries/130681-using-seek-read-csv-file.html)

Jeff

Using Seek to read csv file
 
I was taking the data in a csv file and importing it to an array in vba.

The csv file has 1000 scenarios with 361 time intervals in each scenario -
so there are 3,610,000 total rows. I want the array to be able to grab a
scenario based on an input. So my first attempt was to skip the first
scenarios until I got to the scenario that I wanted, then write to the array
for 360 times.

So if I wanted to pick up scenario number '34' I would write

For i = 1 to (34 * 361)
input #1, temp 'does nothing
Next i

For i = 1 to 360
input #1, Array(i)
next i

But can you use the "Seek" function to skip ahead to scenario 34 then start
reading. Because the way I have it written seems like a waste because I
start reading from the beginning each time - and I have to run a lot of
scenarios so I need it to be as fast as possible.

Thanks for your help on this

Bob I

Using Seek to read csv file
 
Seek function returns a number that indicates where you are in the file.

Jeff wrote:

I was taking the data in a csv file and importing it to an array in vba.

The csv file has 1000 scenarios with 361 time intervals in each scenario -
so there are 3,610,000 total rows. I want the array to be able to grab a
scenario based on an input. So my first attempt was to skip the first
scenarios until I got to the scenario that I wanted, then write to the array
for 360 times.

So if I wanted to pick up scenario number '34' I would write

For i = 1 to (34 * 361)
input #1, temp 'does nothing
Next i

For i = 1 to 360
input #1, Array(i)
next i

But can you use the "Seek" function to skip ahead to scenario 34 then start
reading. Because the way I have it written seems like a waste because I
start reading from the beginning each time - and I have to run a lot of
scenarios so I need it to be as fast as possible.

Thanks for your help on this




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com