UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> FirstLines    


Synopsis

Reads the First Lines of a file.

CODE
' FirstLines
' http://www.utteraccess.com/wiki/FirstLines
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2013-10-27                    strPath: A string that contains the Path where the File is located.
'                                    strFile: A string that contains the Name of the File.
'                                    lngNodes: The Number of Lines to be read.
'
'-------------------------------------------------------------------------------------------------------------------------------------

Public Function FirstLines(strPath As String, _
                          strFile As String, _
                         lngNodes As Long) As String
                     
   Dim oFSO    As Scripting.FileSystemObject
   Dim oTSt    As Scripting.TextStream
   Dim strPF   As String
   Dim strSL   As String
   Dim i       As Long
     
   strPF = strPath & "\" & strFile
   
   Set oFSO = New Scripting.FileSystemObject
   Set oTSt = oFSO.OpenTextFile(strPF, ForReading)
   
   With oTSt
       For i = 1 To lngNodes
           strSL = strSL & .ReadLine & vbCrLf
       Next i
       .Close
   End With
   
   Set oFSO = Nothing
   
   FirstLines = strSL

End Function

Creative Commons License
FirstLines by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 4,694 times.  This page was last modified 23:06, 28 October 2013 by genoma111. Contributions by TheDBguy  Disclaimers