Contents

# Get Statement

Đọc một bản ghi từ một tập tin tương đối, hoặc đọc một dãy byte từ một tập tin nhị phân, vào một biến.

Xem thêm: Câu lệnh PUT

### Syntax:

    Get [#]fileNum, [recordNum|filePos], variable

### Parameters:

fileNum: Any integer expression that determines the file number.

recordNum: For files opened in Random mode, recordNum is the number of the record that you want to read.

For files opened in Binary mode, filePos is the byte position in the file where the reading starts.

If recordNum and filePos are omitted, the current position or the current data record of the file is used.

variable: Name of the variable to be read. With the exception of object variables, you can use any variable type.

### Example:

      Sub ExampleRandomAccess
          Dim iNumber As Integer
          Dim vanBan As Variant REM Phải là Variant
          Dim aFile As String
          aFile = "C:\Users\ThisUser\data.txt"
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Seek #soNguyen,1 REM Vị trí bắt đầu
          Put #iNumber, , "This is the first line of text" ' Fill line with text
          Put #iNumber, , "This is the second line of text"
          Put #iNumber, , "This is the third line of text"
          Seek #iNumber,2
          Get #iNumber, , sText
          Print sText
          Close #iNumber
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Get #iNumber, 2, sText
          Put #iNumber, , "This is a new text"
          Get #iNumber, 1, sText
          Get #iNumber, 2, sText
          Put #iNumber, 20, "This is the text in record 20"
          Print Lof(#iNumber)
          Close #iNumber
      End Sub

      Sub ExampleRandomAccess
          Dim iNumber As Integer
          Dim vanBan As Variant REM Phải là Variant
          Dim aFile As String
          aFile = "~/data.txt"
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Seek #soNguyen,1 REM Vị trí bắt đầu
          Put #iNumber, , "This is the first line of text" ' Fill line with text
          Put #iNumber, , "This is the second line of text"
          Put #iNumber, , "This is the third line of text"
          Seek #iNumber,2
          Get #iNumber, , sText
          Print sText
          Close #iNumber
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Get #iNumber, 2, sText
          Put #iNumber, , "This is a new text"
          Get #iNumber, 1, sText
          Get #iNumber, 2, sText
          Put #iNumber, 20, "This is the text in record 20"
          Print Lof(#iNumber)
          Close #iNumber
      End Sub

Chủ đề Liên quan

Open Statement

Put# Statement

Close Statement