|
-
Oct 19th, 2005, 01:56 PM
#1
Thread Starter
New Member
Get lines from a txt document
Say I have a text document called TEXT
it's a *.txt file.
if I wanted to grab all of the text on a specific line say...line 1, how would I do this with VB?
I would want to put it to a string variable.
-
Oct 19th, 2005, 02:23 PM
#2
Frenzied Member
Re: Get lines from a txt document
 Originally Posted by Zlord
Say I have a text document called TEXT
it's a *.txt file.
if I wanted to grab all of the text on a specific line say...line 1, how would I do this with VB?
I would want to put it to a string variable.
simple as pie ok lets say the file path is selected from cd1.filename heres the code
VB Code:
private sub command1_click
dim temp as string
dim filestuff() as string
Fno = FreeFile
Open cd1.FileName For Input As Fno
temp = Input$(LOF(Fno), Fno)
Close #Fno
filestuff() = split(temp,vbnewline)
temp = filestuff(0)
End Sub
this code opens the file puts it into temp splits it on everyline then temp becomes the first line or for lines u do stuff like filestuff(0 to how many lines)
hope this helped
-
Oct 19th, 2005, 02:27 PM
#3
Thread Starter
New Member
Re: Get lines from a txt document
CD1.filename?
No clue what you're talking about;
-
Oct 19th, 2005, 02:31 PM
#4
Re: Get lines from a txt document
VB Code:
Dim FileIn As String
Open "C:\Text.txt" For Input As #1 ' Open file for input.
Line Input #1, FileIn ' Read line of data.
Text1.Text = FileIn
Close #1 ' Close file.
I don't see why you have to read all the file when you only need the first line. It saves using LOF and Split. It reads the first line from the file and puts this into Text1.Text.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Oct 19th, 2005, 02:33 PM
#5
Frenzied Member
Re: Get lines from a txt document
 Originally Posted by Keithuk
VB Code:
Dim FileIn As String
Open "C:\Text.txt" For Input As #1 ' Open file for input.
Line Input #1, FileIn ' Read line of data.
Text1.Text = FileIn
Close #1 ' Close file.
I don't see why you have to read all the file when you only need the first line. It saves using LOF and Split. It reads the first line from the file and puts this into Text1.Text. 
um he was using line1 as an example but anyways cd1.filename is commondialog1 just the name is changed so less typing involved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|