Microsoft KB Archive/61971

WordBASIC: Macro to Demonstrate File Input/Output

PSS ID Number: Q61971 Article last modified on 06- 7-1991

1.00

MS-DOS

Summary: The following sample macro demonstrates WordBASIC File Input/Output. To understand the macro, you need a basic understanding of the macro commands OPEN, WRITE, READ, CLOSE, CALL, and PRINT. The following is the sample: REM The following subroutine writes the text file to the disk. REM in the active directory.

Sub MAIN

a$ = “Hello,”

b$ = “WordBASIC”

c$ = “is powerful”

Open “FOOBAR.TXT” For Output As #1 Write #1, a$, b$, c$

Close #1

Call OpenRead

End Sub

REM the following subroutine reads the text file from disk. Sub OpenRead

Open “FOOBAR.TXT” For Input As #1

Read #1, c$, d$, e$

Close #1

Print c$ + d$ + e$

End Sub

Result: (Hello, WordBASIC is powerful) is printed in the Status Bar.

More Information: For a discussion of the functions described above, see the “Microsoft Word for Windows Technical Reference” manual. The following are various subjects of interest and pages in the reference manual where you can find the information: CALL ……….Page 99 CLOSE ………Page 99 OPEN ……….Page 103 READ ……….Page 104 PRINT ………Page 104 WRITE ………Page 107

Reference(s):

Additional reference words: w4wmacro