注意
如果 Microsoft Jet 表达式服务在沙盒模式下运行,则本主题中描述的函数、方法、对象或属性将被禁用,这会阻止对潜在不安全表达式进行评估。 有关沙盒模式的详细信息,请在帮助中搜索“沙盒模式”。
返回一个 Long,指定使用 Open 语句打开的文件内的当前读/写位置。
语法
Seek (filenumber)
必需的 filenumber参数是包含有效文件号的整数。
备注
Seek 返回介于 1 到 2,147,483,647 之间的值 (相当于 2^31 – 1) (含)。
下面介绍了每个文件访问模式的返回值。
| 众数 | 返回值 |
|---|---|
| 随机 | 下一条读取或写入的记录的数量 |
|
Binary, 输出, 附加, 输入 |
发生下一个操作的字节位置。 文件中的第一个字节位于位置 1,第二个字节位于位置 2,依此类推。 |
示例
注意
下面的示例演示了在Visual Basic for Applications (VBA) 模块中使用此函数。 有关使用 VBA 的详细信息,请在“搜索”旁边的下拉列表中选择“开发人员参考”,然后在搜索框中输入一个或多个术语。
此示例使用 Seek 函数返回当前文件位置。 该示例假设 TESTFILE 是一个包含用户定义类型的 Record记录的文件。
Type Record ' Define user-defined type.
ID As Integer
Name As String * 20
End Type
对于以随机模式打开的文件, Seek 将返回下一条记录的数量。
Dim MyRecord As Record ' Declare variable.
Open "TESTFILE" For Random As #1 Len = Len(MyRecord)
Do While Not EOF(1) ' Loop until end of file.
Get #1, , MyRecord ' Read next record.
' Print record number to the Immediate window.
Debug.Print Seek(1)
Loop
Close #1 ' Close file.
对于以随机模式以外的模式打开的文件, Seek 返回发生下一个操作的字节位置。 假设 TESTFILE 是包含几行文本的文件。
Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file for reading.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Read next character of data.
' Print byte position to the Immediate window.
Debug.Print Seek(1)
Loop
Close #1 ' Close file.