Home > Software engineering >  Vb to read a data line number in more than 50000 lines of TXT file how to take a certain line column
Vb to read a data line number in more than 50000 lines of TXT file how to take a certain line column

Time:09-27

Such as title, I want to read on line 22250 data what to write, because the file is bigger, use the open input will feign death, and I don't know why always error 9 subscript crossing the line, please help me to write the great god, data files as follows, thank you! Want to provide two kinds of coding:
1. Direct divided into rows and columns, read a line one column of data
2. Used for an array, such as 45001, and then take the bank, then take the following three lines,

CodePudding user response:

The guide into the database to find again,
Directly in the text search is always slow,

CodePudding user response:

 if the number of bytes in a row, you can use the 

The following code in a random way to open the file, the file contains user-defined data types Record Record,

Type Record 'define user-defined data types,
ID As an Integer
The Name As String * 20
End Type

Dim MyRecord As Record 'declare variables,
Open "TESTFILE" For the Random As # 1 Len=Len (MyRecord)
'if you want to open the file in other ways, it is necessary to close the file first,
Close # 1

CodePudding user response:

Using the database, or text files directly as a database table, with Microsoft textdrive direct reading and writing, to handle some simple problem, of course, it is normal, if 50000 lines, typically close to 1 ~ 2 seconds to read time,
I usually deal with about twenty thousand lines of text, but also has a non-standard header, need to open the first remove the CSV file header saved into a standard format, reoccupy textdriver, speaking, reading and writing, each file about 2 seconds
If the speed can not accept, can only use the database import tool, such as SQL server BCP features, imported 50000 rows of data is about 100 ms

CodePudding user response:

Using the database is better!

CodePudding user response:

Don't know whether the text file format specification, if not how many Spaces in a row, can only open the input and 50000 lines, more than 10 m text file?

CodePudding user response:

Thank you, I write out ~ with systemobject and streamline
  • Related