注意
若 Microsoft Jet Expression Service 以沙盒模式執行,則本主題所述的函式、方法、物件或屬性將被禁用,避免評估潛在不安全的表達式。 想了解更多沙盒模式的資訊,請在說明中搜尋「sandbox mode」。
回傳一個 Long ,指定使用 Open 敘述開啟檔案中目前的讀寫位置。
語法
尋找 (檔案號)
所需的檔案號參數是一個包含有效檔案號的整數。
註解
Seek 回傳的值介於 1 到 2,147,483,647 之間 (相當於 2^31 – 1) ,含此。
以下說明每種檔案存取模式的回傳值。
| 眾數 | 傳回值 |
|---|---|
| 隨機 | 下一條記錄的讀取或寫入數量 |
|
二進位, 輸出, 補充, 輸入 |
下一個操作發生的位元組位置。 檔案中的第一個位元組位於位置 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.