2009-11-25 150 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