[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:
Open App.Path & "\worlds.txt" For Input As #1
Line Input #1, WLine
MsgBox WLine
Close #1
But can't seem to edit it to search a specific line.
Thanlks in advance!!
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:
Option Explicit
Private lines() As String
Private Sub Form_Load()
Open App.Path & "\worlds.txt" For Input As #1
lines = Split(Input$(LOF(1), 1), vbCrLf)
Close #1
End Sub
'-----------------------------------
'then something like this
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.
Re: Searching specific line in text file?
Worked a treat, as usual casey :thumb: Cheers!