Using the While or Until Clause in Do Loops

There are four variations of using While or Until. These clauses can be added to either the Do statement or the Loop statement. In every case, the While or Until clause includes some test that evaluates to True or False.

With a Do While <test expression>...Loop construct, the loop is never executed if <test expression> is false. If you are reading records from a text file, you can not assume that the file has one or more records, so you need to test to see whether you are already at the end of file with the EOF function before you enter the loop:

1 Read a text file, skipping the Total lines Open "C:\Invoice.txt" For Input As #1 R = 1

Do While Not EOF(1)

Line Input #FileNumber, Data If Not (Data, 5) = "TOTAL" then ' Import this row r = r + 1

Loop Close #1

0 0

Post a comment