Results 1 to 4 of 4

Thread: About opening files

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    4

    About opening files

    Hi all,ive got a question about reading in data from text files
    Ive got a project with a textbox. If i click the command button i want vb to open the textbox and read in a value from a specific line. How can i do this

    Is it possible to read in a specific line from a textfile as a result of a random number,example if there is a random number of 4 can vd read in the value from line 4 in the file..Hope you can help

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: About opening files

    The are many different ways so the following sample is just a one of them:
    VB Code:
    1. Public Function GetTextFromLine(sFile As String, iLine As Long) As String
    2. Dim sText$, arText() As String, sLine$
    3.  
    4.     Open sFile For Input As #1
    5.         'read entire file into a string variable
    6.         sText = Input(LOF(1), #1)
    7.         'split text into array
    8.         arText = Split(sText, vbNewLine)
    9.         'read specific line
    10.         sLine = arText(iLine - 1)
    11.     Close #1
    12.     GetTextFromLine = sLine
    13.  
    14. End Function
    15.  
    16. 'usage:
    17. Private Sub Command2_Click()
    18.     Text1.Text = GetTextFromLine("c:\temp\test1.txt", 3)
    19. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    4

    Re: About opening files

    Hey thanks very much for the reply

  4. #4

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