tags:

views:

63

answers:

2

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 pos == 6)
{
    //do
}
else
{
    //do noting
}

i need this help in vb6.

Thanks in advance.

+3  A: 

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
Rubens Farias
A: 

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
Svetlozar Angelov
okay, but how to goto next line once reading this line?
pbrp
Line Input reads line by line, you read every line, just do nothing when it starts with 6
Svetlozar Angelov
thanks. its working now.
pbrp