Search code examples
vbscriptreadfilehp-uft

vbScript read file from an specific line


Hello everyone I got a doubt, about how to read a .txt file starting in specific line, I got the line number from I want to start to read, and I'm trying to read it, but always start from the first line

And it takes a several minutes to reach my needed line

Here's my code

'Call F_CMN_GRL_FindObjects(17,15)

strProperty = F_CMN_GRL_GlobalMain(6,17,15,0,"all items" )

strLine = split(strProperty,",")
    Print strLine(0)
strValor = split(strLine(0)," ") 
    Print strValue(1)

numberLine = strValue(1)
Call readFromLine(numberLine)
Function readFromLine(numberLine)

    numberLineEnd =numberLine + 7
    print numberLine
    print numberLineEnd
'   Option Explicit

    Dim oFso : Set oFso = CreateObject("Scripting.FileSystemObject")
    Dim oFile : Set oFile = oFso.OpenTextFile("C:\myFile.txt", 1)
'   Dim myArray()
'   ReDim myArray(0)

    'numberLine it's the number line from I want to start to read and I want to read until numberLineEnd            
    For i = numberLine to numberLineEnd step 1
        strLine = oFile.ReadLine

        print strLine
    Next
        'i = i + 1
        'numberLine = numberLine + 1
End Function 

Solution

  • I've solved it by doing it like this:

    Dim i 
        Do While (i <= numeroLineaFin)
            If (i => numeroLinea) and (i<=numeroLineaFin) Then
    '           If i <= numeroLineaFin Then
    '               tmpstr = tmpstr & oFile.readline & VbCrLf
                    tmpstr = oFile.readline
                    print tmpstr
    '           else
    '            oFile.SkipLine
    '           End If
            else
                oFile.SkipLine
            end if
            i = i + 1
        Loop