Loc Function

See Also3MAGGDE              ExampleGU077M>Low

Returns the current position within an open file.

Syntax

Loc(filenumber)

Remarks

The argument filenumber is the number used in the Open statement to open the file.  You can use any numeric expression71RISN that evaluates to the number of an open file.  For Random files, the Loc function returns the number of the last variable read from or written to the file.  For sequential files, Loc returns the current byte position in the file divided by 128.  For Binary mode files, Loc returns the position of the last byte read or written.


See Also

EOF FunctionLANEOF

LOF FunctionLANLOF

Open Statement103I7PS


Loc Function Example

The example uses the Loc function to report the current position within an open data file.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim I, Msg, NL, PresentLoc, Tmp       ' Declare variables

   NL = Chr(10)                          ' Define newline.

   MakeDataFile                          ' Create sample data file.

   Open "TESTFILE" For Input As #1       ' Open file just created.

   For I = 1 To 50

      Input #1, Tmp                      ' Read some data, and discard.

   Next I

   PresentLoc = Loc(1)                   ' Get location within file.

   Close #1                              ' Close file.

   Msg = "50 data elements have been read from a file of 500. "

   Msg = Msg & "The present location within the TESTFILE file is "

   Msg = Msg & PresentLoc & "." & NL & NL

   Msg = Msg & "Choose OK to remove the sample data file."

   MsgBox Msg                            ' Display message.

   Kill "TESTFILE"                       ' Delete file from disk.

End Sub

 

Sub MakeDataFile ()

   Dim I                                 ' Declare variable.

   Open "TESTFILE" For Output As #1      ' Open file for output.

   For I = 1 To 500                      ' Generate random values.

      Print #1, Int(501 * Rnd)           ' Put data in file.

   Next I

   Close #1                              ' Close file.

End Sub