Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

附註: 如果 Microsoft Jet Expression Service 在沙箱模式中執行,會停用本主題中所述的函數、方法、物件或屬性,以免評估可能不安全的表達式。 如需沙盒模式的詳細資訊,請在 [說明] 中搜尋「沙盒模式」。

傳回指定使用 Open 語句開啟之檔案中目前讀/寫位置的 Long。

語法

搜尋 ( 編號 )

必要的 檔案編號引數 是包含有效 檔案編號的整數。

註解

搜尋 會傳回 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

對於以隨機模式開啟的檔案, 搜尋 會傳回下一筆記錄的數目。

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.

對於以隨機模式以外的模式開啟的檔案, 搜尋 會傳回下一個作業的位元組位置。 假設 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.

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×