loading formatted data in VBA from a text file -
I am looking for the best way to load formatted data in VBA. I've spent some time trying to find something like C-like or Fortran such as the fscanf
type function, but without success
Actually I have many (100,000) rows in 10 Want to read millions of numbers from a text file with numbers (excluding the last line, maybe 1-10 numbers). Numbers are different from the spaces, but I do not know the width of each field already (and this width change between the data block). E.g.
397143.1 396743.1 396343.1 395943.1 395543.1 394343.1 394743.1 394343.1393943.1393543.1 -0.11 -0.10 -0.10 -0.10 -0.10 -0.09 -0.09 -0.09 -0.09 -0.09 0.171 0.165 0.164 0.162 0.158 0.154 0.151 0.145 0.157 0.20 9
First I used the middle
function but in this situation I can not do it, because I do not already know the breadth of each area, besides it There are many lines to load in Excel Sheet. I can think of the method of a cruel force in which I look at the character continuously and determine whether it is a place or a number, but it seems very clumsy.
How do I write the formatted data, but it sounds easy but is interested in pointers - just format each string and & amp;
The following snippet will read the white space-delimited number from a text file:
In the form of # 1 for input, give "YourDataFile.txt" as "double number" in the form of a double open, do something with input # 1, some numbers / some numbers ... .. Close the loop # 1 Update: With a variable number of items on each line, you can read one line at a time: some numbers like asth Do not open "YourDataFile" for input as long as slow startPosition, as long as the slow temp in the form of a string, while not in the form of # 1 (EOF (1)) startPosition = Seek (1) // capture the current file position 'line input # 1, temporary' // read a complete line 'and position = sic (1)' // 'determine the position of the // end-of-line file' 1, the initialization '// Return to the beginning of the line '/ numbers from the file till the end of the current row Read while (E of (1)) and ((1) lt; End page) input # 1, some number '// do something with something here number ...' close loop loop # 1
Comments
Post a Comment