一个好老好老的老程序员了。
全部博文(915)
分类: WINDOWS
2006-11-07 10:53:16
文章编号 | : | 181788 |
最后修改 | : | 2005年6月17日 |
修订 | : | 2.0 |
Open pathname For mode [access] [lock] As [#]filenumber [Len=reclength]
Open 语句语法具有下列组成部分。 Part Description --------------------------- pathname Required. String expression that specifies a file name may include directory or folder, and drive. mode Required. Keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access. access Optional. Keyword specifying the operations permitted on the open file: Read, Write, or Read Write. lock Optional. Keyword specifying the operations permitted on the open file by other processes: Shared, Lock Read, Lock Write, and Lock Read Write. filenumber Required. A valid file number in the range 1 to 511, inclusive. Use the FreeFile function to obtain the next available file number. reclength Optional. Number less than or equal to 32,767 (bytes). For files opened for random access, this value is the record length. For sequential files, this value is the number of characters buffered.
Sub OpenExample()
Dim sFirst, sLast, sAddress, sCity, sState, sZip As String
' CREATE DATA FILE
' Open file for input.
Open "Datafile.txt" For Output As #1
' Write data to file.
Write #1, "John", "Doe", "An Address", "A City", "A State", "A Zip"
' Close File.
Close #1
' RETRIEVE DATA FROM FILE
' Open file for input.
Open "Datafile.txt" For Input As #1
' Loop until the end of file is reached.
Do While Not EOF(1)
' Read data into variables.
Input #1, sFirst,sLast,sAddress,sCity,sState,sZip
' Print data to Debug window.
Debug.Print sFirst,sLast,sAddress,sCity,sState,sZip
Loop
' Close file.
Close #1
End Sub
该宏创建或打开称为 Datafile.txt 文件并将逗号和引号分隔数据放入文件。 可再后面使用输入 # Statement 检索数据。
• | Microsoft Word 97 Standard Edition |