Results 1 to 1 of 1

Thread: GetLineInfo

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    GetLineInfo

    I just made a function that will read between specific lines for you, say you want to only get the lines 20-40 in your text file, you use this. If you only want one line, just use the same number for upper and lower

    VB Code:
    1. Option Explicit
    2.     Dim str2buff As String
    3.  
    4. Private Sub Form_Load()
    5. Call GetLineInfo("C:\Documents and Settings\Jason\Desktop\response.txt", 20, 40)
    6.                MsgBox str2buff
    7. End Sub
    8.  
    9. Public Function GetLineInfo(txtfile As String, lowerline As String, upperline As String) As String
    10.     Dim ff As Integer
    11.     Dim strbuff As String
    12.     Dim LineCount As Long
    13.     Dim yay As String
    14.     LineCount = 0
    15.         ff = FreeFile
    16.         lowerline = lowerline - 1: upperline = upperline - 1
    17.              Open txtfile For Input As #ff
    18.                Do Until EOF(ff)
    19.                 LineCount = LineCount + 1
    20.                 Line Input #ff, yay
    21.                 yay = vbNullString
    22.                     If LineCount >= lowerline And LineCount <= upperline Then
    23.                  Line Input #ff, strbuff
    24.                     str2buff = str2buff & vbNewLine & strbuff
    25.                     ElseIf LineCount > upperline Then
    26.                         Exit Function
    27.                     End If
    28.                Loop
    29. End Function
    enjoy
    Last edited by |2eM!x; Jun 2nd, 2005 at 07:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width