2009-11-25 226 views
0

我正在阅读使用vb6代码的文本文件。我的要求是,如果行以6开头,那么我需要读取该行,否则我必须离开该行并转到下一行。任何人都可以帮助我如何做到这一点?如何读取txt文件。?

if (start pos == 6) 
{ 
    //do 
} 
else 
{ 
    //do noting 
} 

我需要vb6中的帮助。

在此先感谢。

回答

0

类似的东西

Dim nFileNum As Integer, sNextLine As String 
nFileNum = FreeFile 
Open "C:\log.txt" For Input As nFileNum 
Do While Not EOF(nFileNum) 
    Line Input #nFileNum, sNextLine 
    If Mid(sNextLine, 1, 1) = "6" Then 
     'here what you want 
    End If 
Loop 
Close nFileNum 
+0

好的,但如何转到下一行一次读这条线? – pbrp 2009-11-25 15:59:36

+0

行输入逐行读取,您读取每一行,只是无所事事,当它开始于6 – 2009-11-25 16:14:08

+0

谢谢。它的工作现在。 – pbrp 2009-11-25 20:38:37

3

试试这个

Const ForReading = 1 
Const TristateUseDefault = -2 

Set oFS = CreateObject("Scripting.FileSystemObject") 
Set oFile = oFS.GetFile("yourfile.txt") 
Set oStream = oFile.OpenAsTextStream(ForReading, TristateUseDefault) 
Do While Not oStream.AtEndOfStream 
    sRecord=oStream.ReadLine 
    If Substring(sRecord, 1, 1) = "6" Then 
     ' do 
    Else 
     ' do nothing 
    End If 
Loop 
oStream.Close