how to read txt file.?
I am reading textfile using vb6 code. My requirements are if the line starts with 6 then i need to read that line otherwise i have to leave that line and goto next line. can anyone help me how to do that?
if ( start po开发者_高级运维s == 6)
{
//do
}
else
{
//do noting
}
i need this help in vb6.
Thanks in advance.
Try this
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
Something like that
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
精彩评论