VBA通过以相反的顺序读取行大的文本文件行文本文件、顺序、VBA

2023-09-11 02:29:38 作者:安于命@

VBA问题

有一个大的日志文件(约50万线),我需要行读这本书是在相反的顺序线,即从最后一行到第一行。 我知道我可以在Microsoft脚本运行时参考使用FileSystemObject的,但目前还没有这样的选项一样的逆转的在文本流ReadLine方法

There is a large log file (around 500,000 lines), I need to read it line by line in reverse order, i.e. from the last line to the first line. I know I can use FileSystemObject in the Microsoft Scripting Runtime reference, but there is no such option like reverse for ReadLine Method in TextStream

现在,我能想到的唯一的办法是这样的,有一个计数器,并跳过previous线每个我读了线,但肯定这是不是足够好。任何建议code /算法中会更加AP preciated。

Now, the only way I can think of is like this, has a counter and skip previous lines for each of the line I read, but definitely this is not good enough. Any suggestion code/algo will be much appreciated.

推荐答案

如果您的日志是一种数据库的使用领域,允许以确定的顺序(有一个日期字段或行号字段),如果是的话,你可以尝试使用ADO的解决方案与SQL查询来读取日志以相反的顺序(ORDER BY ... DESC)。所以,你将能够从上次读取到第一位。或者generally-尝试使用ADO。

If your log is a kind of database with field which allows to determine the order (is there a date field or line number field), if so you could try to use ADO solution with SQL query to read the log in reverse order (ORDER BY ... DESC). So, you will be able to read from last to first. Or generally- try to use ADO.