Results 1 to 3 of 3

Thread: [SORTED]Searching specific line in text file?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Resolved [SORTED]Searching specific line in text file?

    I have a text file with about 84 lines of text or so. What i'm trying to do it when someone types 32 in a box then a string is changed to what is on line 32 in the text file.

    For example if line 64 is hello, when the user types in line 64 in the textbox then the string MyString will = hello.

    I want this to be as easy as possible please. Im currently using

    VB Code:
    1. Open App.Path & "\worlds.txt" For Input As #1
    2. Line Input #1, WLine
    3.   MsgBox WLine
    4. Close #1

    But can't seem to edit it to search a specific line.

    Thanlks in advance!!
    Last edited by BefunMunkToloGen; May 2nd, 2005 at 12:20 PM.

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Searching specific line in text file?

    i would open the file and put the contents straight into a array by using split and the delimiter of vbcrlf in form load then you dont need to keep opening the file
    VB Code:
    1. Option Explicit
    2. Private lines() As String
    3.  
    4. Private Sub Form_Load()
    5.  
    6. Open App.Path & "\worlds.txt" For Input As #1
    7.  lines = Split(Input$(LOF(1), 1), vbCrLf)
    8. Close #1
    9.  
    10. End Sub
    11.  
    12. '-----------------------------------
    13. 'then something like this
    14. Text2.Text = lines(Val(Text1.Text) - 1)
    you would also need to check the value in textbox 1 isnt more than upperbound lines +1
    casey.
    Last edited by vbasicgirl; May 2nd, 2005 at 12:10 PM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Searching specific line in text file?

    Worked a treat, as usual casey Cheers!

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