Microsoft KB Archive/68122

= BASIC Can Write Files for MS Excel Spreadsheet =

Article ID: 68122

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 1.0
 * Microsoft QuickBasic 1.01
 * Microsoft QuickBasic 1.02
 * Microsoft QuickBASIC 1.0b
 * Microsoft QuickBASIC 1.0b
 * Microsoft QuickBasic 2.0
 * Microsoft QuickBasic 2.01
 * Microsoft QuickBasic 3.0
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1
 * Microsoft BASIC Interpreter 2.0
 * Microsoft BASIC Interpreter 2.1 for Macintosh
 * Microsoft BASIC Interpreter 3.0 for Macintosh
 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft GW-BASIC Interpreter 3.20
 * Microsoft GW-BASIC Interpreter 3.23
 * Microsoft GW-BASIC Interpreter 3.22
 * Microsoft GW-BASIC Interpreter 3.23

-



This article was previously published under Q68122



SUMMARY
Microsoft QuickBASIC can manipulate ASCII text files used by Microsoft Excel in either comma separated values (CSV) or tab separated values (TEXT) file formats.

QuickBASIC can generate these file formats with the standard BASIC statements OPEN, CLOSE, PRINT, and WRITE.

This information applies to Microsoft QuickBASIC versions 1.00, 2.00, 3.00, 4.00, 4.00b, and 4.50 for MS-DOS; Microsoft BASIC Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2; Microsoft BASIC Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2; Microsoft BASIC Interpreter versions 2.00, 2.01, and 3.00 for Apple Macintosh; Microsoft QuickBASIC versions 1.00 and 1.00b for Apple Macintosh; Microsoft BASIC Compiler version 1.00 for Apple Macintosh; and GW-BASIC Interpreter versions 3.20, 3.22, and 3.23 for MS-DOS.



MORE INFORMATION
Microsoft Excel supports two TEXT file formats: tab (TEXT) files, and comma (CVS) delimited files. Both of these files contain the textual information in each cell, no formulas, and a delimiter between each column and a carriage return plus linefeed (CR/LF) at the end of each row on MS-DOS computers (but just CR ending each row on Macintosh computers).

Tab delimited files have a tab character separating each column. To generate a tab character in BASIC, use the CHR$ function with a parameter of 9. For example, Tab$ = CHR$(9) Comma delimited files have a comma character separating each column. There are several ways to generate a comma in the output file. One way is to use BASIC's CHR$ function with a parameter of 44. For example, Comma$ = CHR$(44) If a cell contains a comma, the value from the cell will be enclosed in double quotation marks. In BASIC, you can use the WRITE command to place an item in double quotation marks.

BASIC Code Example
REM ** Create a COMMA Delimited File ** Comma$ = CHR$(44) OPEN &quot;EXCEL.CVS&quot; FOR OUTPUT AS #1 PRINT #1, &quot;Employee Information&quot; PRINT #1, &quot; &quot; PRINT #1, &quot;First&quot;; Comma$; &quot;Last Name&quot;; Comma$; &quot;Age&quot; PRINT #1, &quot; &quot; PRINT #1, &quot;Loren&quot;; Comma$; &quot;Moe&quot;; Comma$; 35 PRINT #1, &quot;Arthur&quot;; Comma$; &quot;Nelson&quot;; Comma$; 21 PRINT #1, &quot;George&quot;; Comma$; &quot;Merriman&quot;;Comma$; 30 PRINT #1, &quot; &quot; CLOSE #1

REM ** Creates a TAB Delimited File ** Tab$ = CHR$(9) OPEN &quot;EXCEL.TXT&quot; FOR OUTPUT AS #2 PRINT #2, &quot;Employee Information&quot; PRINT #2, &quot; &quot; PRINT #2, &quot;First&quot;; Tab$; &quot;Last Name&quot;; Tab$; &quot;Age&quot; PRINT #2 &quot; &quot; PRINT #2, &quot;Loren&quot;; Tab$; &quot;Moe&quot;; Tab$; 35 PRINT #2, &quot;Arthur&quot;; Tab$; &quot;Nelson&quot;; Tab$; 21 PRINT #2, &quot;George&quot;; Tab$; &quot;Merriman&quot;; Tab$; 30 PRINT #2, &quot; &quot; CLOSE #2

Additional query words: QuickBas BasicCom MQuickB

Keywords: KB68122

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.