' ' ReadNumbersFromTextFile.bas ' Read a comma-separated list of doubles from a text file. ' ' Author: Tom McCollough ' Organization: Engineering Geometry Systems ' Date: 4/2/02 ' Programming Environment: Sax Basic for FeatureCAM V9 ' Copyright (c) 2002, Engineering Geometry Systems ' ' General Description ' ' The macro opens a text file and reads three doubles until the end of file. ' The sample input file would look like this: ' ' 1.2, 2.3, 3.4 ' 10, 20, 30 ' 100.2, 200.3, 300.4 ' ' When you create the sample file from the example above, be sure to remove ' the quote and the blank at the beginning of each line. ' ' When you run the macro, you should see the following in the debug window: ' ' A IS 1.2 ' B IS 2.3 ' C IS 3.4 ' A IS 10 ' B IS 20 ' C IS 30 ' A IS 100.2 ' B IS 200.3 ' C IS 300.4 ' CLOSING FILE ' ' Note that the macro handles integers or doubles. ' ' Limitations ' ' This macro demonstrates the simple parsing mechanism provided by Sax Basic ' in the form of the Input instruction. The parsing is so simple that if ' there are any errors in the input stream, then the macro will simply halt. ' More robust parsing mechanisms need to be programmed in a more interesting ' and careful way. ' ' Specifically: ' ' 1. This macro is error prone regarding the end-of-file test. If there are ' blank lines at the end of the file, then the macro will halt. ' ' 2. The macro will halt if the input stream contains any errors, i.e. if there ' are strings in the input stream. ' Dim A As Double Dim B As Double Dim C As Double Sub Main Open "c:\dev\macros\sampleNumbers.txt" For Input As #1 While Not EOF(1) Input #1,A,B,C Debug.Print "A IS "; A Debug.Print "B IS "; B Debug.Print "C IS "; C Wend Close #1 Debug.Print "CLOSING FILE" End Sub