C1Awk Reference > C1Awk Properties > CurrPos Property |
Returns or sets the position of the current line within the file.
[form!]C1Awk.CurrPos[ = value As Long ]
This property is useful when you want to save the position of current line so that you can easily return to it later.
When you get or set the CurrPos property, the file specified by the FileName property should be open. You may open the file by setting the Action property to acScan or acNextLine, or you may use the FindLine property.
After you set the CurrPos property, the file handle will be repositioned. You must then read the line by setting the Action property to acNextLine.
The example below illustrates how you can do this:
Example Title |
Copy Code
|
---|---|
' GetStringPos --------------------------------------------- ' Look through a file for a line containing a string. ' Return the position where it was found or -1 if not found ' ---------------------------------------------------------- Function GetStringPos(fname$, fstr$) As Long awk.FileName = fname ' set file name awk.FindLine = fstr ' look for string awk.Action = arClose ' close file If awk = "" Then ' not found GetStringPos = -1 Debug.Print fstr; " Not found in "; fname Else ' found GetStringPos = awk.CurrPos Debug.Print fstr; "found at "; awk.CurrPos End If End Function ' ReadAtPos------------------------------------------------- ' read a line at a specified position in a file ' ---------------------------------------------------------- Sub ReadAtPos(savedpos&) awk.Action = acNextLine ' force file open awk.CurrPos = savedpos ' go to position awk.Action = acNextLine ' read line Debug.Print awk ' show line awk.Action = acClose ' close file End Sub |
Long