Access和VBA读取文本文件,每行超过255个字符 [英] Access and VBA read text file with more than 255 characters per line
本文介绍了Access和VBA读取文本文件,每行超过255个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用VBA在Access中读取文本文件.代码如下:
I am trying to read a text file in Access using VBA. The code is as follows:
Open "C:\Test\test.txt" For Input As #1
Dim MyString as String
Dim x as integer
x = 0
For x = 0 to 100
Input #1, MyString
MsgBox MyString
Next x
因此,此代码的目的是逐行遍历一个文本文件并打印出来.但是,文本行可能超过255个字符.有没有办法读取超过255个字符的行并将其存储在VBA中?谢谢.
So the purpose of this code, is to iterate through a text file reading line by line and printing it out. But there is the probability in which the line of text exceeds 255 characters. Is there a way to read lines over 255 characters and store them in VBA? Thank you.
文本文件示例
1110; TESTING ; 1111; TESTING2 ; 5; 999990981; 10-30-2011; 12-01-2011; 133370001; 133370001; 133370001; 133370001; 133370001; 133370001; 133370001; 133370001; 133370001; 133370001; 133370001; 133370001; F; 13371; 1; TEST1 ; 000000000; 133370001; 0; TEST ; TESTTES ; TEST ; 501; 10001; 0; 00001;
1112; TESTING ; 1113; TESTING2 ; 3; 999990982; 10-02-2011; 10-30-2011; 133370002; 133370002; 133370002; 133370002; 133370002; 133370002; 133370002; 133370002; 133370002; 133370002; 133370002; 133370002; F; 13372; 2; TEST2 ; 000000000; 133370002; 0; TEST1 ; TESTTESTT ; TES ; 502; 10002; 0; 00002;
1113; TESTING ; 1114; TESTING2 ; 21; 999990983; 03-01-2011; 10-02-2011; 133370003; 133370003; 133370003; 133370003; 133370003; 133370003; 133370003; 133370003; 133370003; 133370003; 133370003; 133370003; F; 13373; 3; TEST3 ; 000000000; 133370003; 0; TTESTTESTT ; TESTTESTTES ; TESTTES ; 503; 10003; 0; 00003;
推荐答案
Sub ReadLines()
Dim sInput As String
Dim i As Long
Open "C:\Users\dick\test.txt" For Input As #1
Do While Not EOF(1)
Input #1, sInput
Debug.Print Len(sInput), sInput
Loop
End Sub
我知道
468 1110; ...
469 1112; ...
469 1113; ...
所以我没有看到限制
这篇关于Access和VBA读取文本文件,每行超过255个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文