0

Some lines in the code are skipped while exceuting test in UFT through ALM. My code is below to read number of lines from the text file:

Function GetTextFileLineCount(Filepath)

    Const ForReading = 1
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tso = fso.OpenTextFile(Filepath,ForReading)

    tso.ReadAll

    GetTextFileLineCount = tso.Line

    tso.Close

    Set tso = Nothing
    Set fso = Nothing

End Function

When I run it locally, ir runs through all the lines and exceutes succesfully. When I ru this test from ALM lines from set tso to tso.close are skipped for exceuting. Could you please suggest the solution for the same.

  • 1
    Lines should never be skipped. They may execute with error and move to the next line, but should not be skipped. Can you explain what makes you think they are being skipped? – HgCoder Sep 05 '14 at 12:28
  • When I run in debug mode , and click step over for each step after Set fso = CreateObject("Scripting.FileSystemObject") line , it directly goes to set tso = nothing line, and values of tso, GetTextFileLineCount are shown as empty. – purushotham Sep 10 '14 at 07:05
  • Extremely odd. Perhaps it's executing more than the debugger shows. Try inserting statements like `MsgBox "Opening file"` between each of the statements in your function. Maybe even display the line number before you assign the return value of the function. – HgCoder Sep 10 '14 at 10:53
  • I added MsgBox "Opening file" between each line , MsgBox statement gets exceuted, but GetTextFileLineCount value is empty. I guess UFT is unable to read the file properly. It works absolutly fine when directly run from UFT – purushotham Sep 11 '14 at 06:15
  • What if you put `MsgBox "Line Count = '" & tso.Line & "'"` to display the line count before you set the return value? Have you verified that the file path you pass in is accurate? – HgCoder Sep 11 '14 at 11:43
  • I used Set tso = fso.OpenTextFile(Filepath, 1, True) instead of the above line. It worked. :) – purushotham Sep 11 '14 at 11:48
  • Interesting, but glad you fixed it! Please post your solution as an answer and mark it as confirmed so that this question doesn't look unanswered. – HgCoder Sep 11 '14 at 15:01

0 Answers0