开发者

how to read txt file.?

开发者 https://www.devze.com 2022-12-12 17:56 出处:网络
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 t

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号