Content area
Full Text
How AutoLISP and VBA deal with files.
In CADALYST's January 1999 issue, we delved into the similarities and differences between AutoLISP and VBA. As I stated then, it's easier to translate an existing portion of AutoLISP into VBA than to reinvent it. It's also easier to compare the two codes if the variable names remain the same.
For more on getting started with VBA, go to our Web site at www. cadonline. com/features/ vbasic. htm#intro.
File Input/output
Many programs need to read and write data to a file. AutoLISP and VBA provide some general filehandling functions and statements for I/O (input and output) to a disk system.
Word processors, spreadsheets and database programs create a variety of files. However, AutoLISP can only process an ASCII text file, which many programs can produce. You can open files from most Windows programs with VBA. For the purpose of comparison, this article will look only at file I/O for ASCII text files.
Opening files
File processing is relatively simple. Before you can write a file to disk or read it, you must open it. Once it's open, you can read and write data one character or a full line at a time. This holds true with both AutoLISP and VBA programs.
To open a file with AutoLISP, use the expression: (setq #1 (open "c:/temp/test.txt" "w")). AutoLISP returns a file handle or pointer that is set to variable #1.
Because you can write to and read from a file, you must specify which access mode you need at the time you open...