我正在使用vb6代码阅读文本文件。我的要求是如果行以6开头然后我需要读取该行,否则我必须离开该行并转到下一行。任何人都可以帮我怎么做?
if ( start pos == 6)
{
//do
}
else
{
//do noting
}
我在vb6中需要这个帮助。
提前致谢。
答案 0 :(得分: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
答案 1 :(得分: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