Read Text File Line-By-Line
I need to take a text file, read it line by line, and put certain lines into an array...
I need some help on the reading line by line part...
Can anyone steer me in the right direction? I don't need to read it all into an array, just 1 line at a time, and if the line meets certain criteria, put THAT LINE in an array...(I can handle the "if it meets certain criteria" part...)
Thanks!!
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Line By Line Text File Read And Correct Each Line
Can anyone help me create a small program or have any pointers
on pieces of code that reads a text file from folder "unfixed" then
fix the contents and then store the corrected contents
in another folder "fixed" and then move the file in folder "unfixed" to folder "old"
Details of contents.
There is a space infront of each line that should be removed.
Between the first group of numbers and the second there should be a zero for every space.
Then after the second group of numbers there should be just one space and the rest trimed off.
011531015222360000500355 3350505212004 50122
011531015222360000500363 5336305212004 6255
011531015222360000503465 2404505212004 50022
011531015222360000503463 1345205212004 50025
02153101522236 13 1503256
The @ symbol represents where a space should be.
I would like to read the file and then correct it and then
place the fixed contents in another folder with the original name.
Below is how I would like it to look.
01153101522236000050035500000003350505212004@
01153101522236000050036300000005336305212004@
01153101522236000050346500000002404505212004@
01153101522236000050346300000001345205212004@
021531015222360000000013@
Read, Find A Line And Delete The Line In Text File
Hi, I am writing codes to do the following things: read a line from a text file, if this is a matched line, delete the line and go to the next line.
Can any one give me some direction? Such as access mode, method to use, etc.
Thanks.
.Input ( Read Contentsof Text File - Line By Line )
I'm trying to import Data from a text file, which includes the following,
Vessel Name
000115600
000025600
000000000
000089000
000019000
000000000
6670.43
The above file is updated every five minutes and I wish to retreive this data in
order to perform calc's and then display a completion time for a process on the
User Form.
code:-----------------------------------------------------------------------------
---
Open "YourFile.txt" For Input As #1
While Not EOF(1)
Input #1, YourVariable
List1.Additem YourVariable
Wend
Close #1
--------------------------------------------------------------------------------
Instead of adding to a list as in the above example, I want to process it Line by
Line ( How do I achieve this using .Input ).
Help
How To Read Text File Line By Line?
Dears Friends,
I am coding a program to read emails.
Is there a way to read the email body text line by line ? if not possible, how can I set the bodytext to a text file and use that text file to read line by line?
Here is my psuedocode for reading email line by line:
With .bodytext
Loop from line 1 to EOF
If line x has string "Hello" then
If line x + 1 has "Money" then
forward this to youare@somewhere.com
end if
end if
End loop
End with
Here is my psuedocode for set .bodytext to file.
dim sFirststring as string
dim sSecondstring as string
With .bodytext
save the .bodytext to a file name A.txt
sFileName = " C:A.txt"
Open sFileName For Input As #1
Do Until EOF(1)
Input#1, sFirststring, sSecondstring
If Mid(sFirststring, 1, 1) = "Hello" Then
If Mid(sSecondstring, 1, 1) = "Money" Then
forward this to youare@somewhere.com
End IF
End If
Loop
Thanks,
Bil
Read Line By Line Of Text File And Move Content To Excel Record By Record
Hi,
i am trying to move the selective information in the text file to Excel sheet record by record using VB.Can u help me in this regard.
The contents in text file is like:
"http://www.commerx.com/contact.html","inforequest@commerx.com"
"http://www.commerx.com/contact.html","ClientSupport@commerx.com"
"http://www.commerx.com/services-intranets.html","intranets@commerx.com"
"http://www.davacosourcing.com/company/","bignews@davacosourcing.com"
"http://www.davacosourcing.com/company/","careers@davacosourcing.com"
.
.
.
.
.
.
The above information need to be moved in Excel sheet record by record as:
http://www.commerx.com/contact.html inforequest@commerx.com
http://www.commerx.com/contact.html ClientSupport@commerx.com
http://www.commerx.com/services-intranets.html intranets@commerx.com
http://www.davacosourcing.com/company/ bignews@davacosourcing.com
http://www.davacosourcing.com/company/ careers@davacosourcing.com
.
.
.
.
..
Please do help in this regard as there are more than 1000 information that has to moved in the above pattern.
Thanx
babu
Line Input #1, Line...how Do I Read Ahead One Line (or Back Up One Line)
I am loading a file line by line using the LIne Input but at one point i need to look ahead at the next line to decided what to do on the current line...how do i look ahead one line? or how do i use the line Input function and then back up? Any help would be greatly appreciated.
Shane Thomas
p.s. please email replys in addition to the reply of post too
shathoma@nmsu.edu
Read A Word In A Line Of Text And Delete That Line
I have some aim logs that I'm going to put in .txt format, and I want to be able to delete the text that the other person has written.
Is there a way for me to specify a screen name and have the program delete that line of text?
Thanks,
Brad
How To Read Rich Text Box Content Line By Line
Hi all. I got a rich text box and i wonder how i can read each line of it one by one. For example i want to read each line of it and display it in massage box.
Furthermore, if i have 10 line of content in textbox how i can refrence each line and display it in massage box?
I be happy if some one show me how this can be done.Thanks
Run Time Error When Read File Line By Line
I'm trying to read a txt file line by line that I can stop reading at any place I want.
Below is the code:
VB Code:
Do While Not EOF(1) Line Input #1, fString Text1.Text = Text1.Text + fString + vbCrLfLoop
The problem is, if the txt file has empty lines at the end of it, it will have run time error : "Input past end of file".
Does anyone know how to solve this problem?
Thanks in advance!
[Help] Read Last Line Of A Text File
Hey Guys,
Im in the process of trying to make an application and have come to a stand still, unable to find out how to read _just_ the last line of a text file.
The problem is that, instead of loading XXX.txt which could contain 2000+ lines, then getting the last line, causing major overhead, I am trying to find a method for getting just the last line.
Thanks in advance,
Regards,
Mark
Read A Text File Line
Is there any way to make a VB program read a certain line from a text file?
If you have a computer or Windows 98 question, ask me.
Read Text Per Line From File
Well, my file is named "config.usof" (its just a text file). I've got one value per line and I'd like to dim a value for each line... any help? Thanks guys... ur savin my project
Read Last Line Of Text File
Hi Guys,
I needed some help regarding file reading in VB 6. I am writing a program that needs to insert a record in a text file. The text file has following format..
Date, Time, Open Price, Close price
Now i need to insert record only if date is greater than last date in file.
So everytime I need to insert record, I have to open file and read sequentially and then I reach last record. This takes time.
IS there a way to read such file in binary or whatever so that i can get last record straight away or very quickly without going thru all records one by one.
If there is can anyone post a small code.
[Records in the (text) file is like -
01/01/2006, 1100, 123.33, 155.55
01/01/2006, 1130, 122.22, 134.33
01/01/2006, 1200, 112.22, 124.33
so on ... ]
Thanks a lot,
Cheers,
GR
How Can I Go To Some Line In Text File For Read It?
If I have some text file that contain many line. And I want to go to some line for read it that line. How can I coding this case in VB?
I know that I can use "For" loop to go to that line but I think VB may be has some better way to go to that line directly
How To Read Certain Line In Text File
Is there a way to read certain line of text within a text file?
What I have is a text file that is sorted A-Z. And let just say
when the user clicks on words begin with 'b', I want to go
to a know lines within my text file. My text file is not fixed lenght!
Let just say a = 1, b = 50, c = 100 etc... So how can I read
line 50 when user clicks the b word?
Thanks in advance for the help.
Read First Line Of Text File
Is it possible to just read in the first line of a text file? I really don't want to load the whole thing into memory just the first line.
Thanks.
How Read Each Line In A Text File ?
Hello everybody
I want my VB 5 Project to read a text file line by line to put each line in an array.
Thank you very much if you can help me.
Read (eg: Line No 10) From A Text File
Hello ,
I have this text file , if i find a particular string in a line then i want to delete the line.I can find the string position with the instr function, i want to start reading from that line onwards instead of having to go through the entire file to come across that line
any ideas how do i ??
thank you for your help
How To Read Last Line In A Text File?
Hi all,
I want to read last line in a text file but don't want to browse through all other lines before approach the last line. How can I do it?
Thank you!
How To Read 1st Variable Line By Line From A .txt File
1st question. Is it easier if I use a database I assume?
Say for example I have a file named test.txt which looks like this
"Test1"
"Tst2"
"tt3"
And I do a search for "Tst2" how would I go through file to find that?
Open test.txt for input #1
white not EOF(1)
????
I am totally lost here. And are there any thorough tutorials online for visual basic 6 or a GOOD quality book that would touch on things like this an DBGrid's? The only one I have is too basic.
Thanks in advance and I apologize for the question but I can't find a resolution anywhere.
Open File And Read Line By Line
how would i open a file and read line by line?
i have it opening and reading this way
FNum = FreeFile()
Open fileIn For Binary Access Read As #FNum
FBuf = Space$(LOF(FNum))
Get #FNum, , FBuf
correction = FBuf
Close #FNum
but i want to be able to read each sentence at a time and for there to be a loop for the whole text file that goes through sentence by sentence
the file looks like this
<blah blah blah>
<blah blah blah>
...
basically i want to read each <blah blah blah> at a time
Any ideas??
Read From A Text File One Line At A Time
hello i've written this function bellow to read information from a text file.
Code:
Private Sub cmdLoadConfig_Click()
Dim strTextLine As String
Open "C:abcd.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strTextLine
txtRangeSelect.Text = strTextLine
Loop
Close #1
End Sub
i was just wondering how to read one line at a time. so i can make a variable equal to a certain line.
eg
variable1 = line 1 of the text file
variable2 = line 2 of the text file
any ideas?
thanks a lot
Read Text File Until Blank Line
Hello, I am trying to read a text file into a string until a blank line is reached. For example,
textfile.txt
this is the first line
I want these lines read
I do not want these lines read
or this one
EOF
I have tried using Line Input with If line = "" exit do, however, it seems only to load one line, if any....
So how is a blank line in a file detected?
Thanks so much
Greg
Read Random Line From Text-file
Hi!
I want to read a random line from a text file. My text file has 315 lines in it. Here is what I have written so far:
Code:
Dim number As Integer
Dim line As Integer
number = Int(300 * Rnd) + 1
Open App.Path & "words.txt" For Input As #1
For line = 1 To number
Input #1, line
Next
MsgBox (line)
Close #1
But every time I try to run this, the debugger informs me about Run-time error '62': Input past end of file.
The problem can't be with the randomizer because I checked the output once and it said that the number was 8. And since my text-file is 315 lines long, I really can't figure what is the problem.
Can anyone help me?
Read/delete Line From Text File
Hi
I use VB to read a line of code from a text file and store it in a variable - no problem
what I would like to be able to do is
read the first line from a text file store in a variable
then delete that line from the text file
then repeat the process for as many times as I like
So I go to the first line read it store it delete it – read it store it delete it etc etc
Any ideas how this could be done?
Thanks
Read From A Text File One Line At A Time
Sorry to revive an old thread but its probably better then adding a new one
Im using a code to download a file and then read from that file, the file downloads OK, all the text in the downloaded file is correct but this code doesnt seem to be working
Code:
intFile = FreeFile()
Open CurDir & "
otice 2331.dat" For Input As #intFile
Line Input #intFile, strLinenews1
Line Input #intFile, strLinenews2
Line Input #intFile, strLinenews3
Close #intFile
it works if i use just the Line Input #intFile, strLinenews1, if i put the other 2 i get a Input past end of file, but im sure the file has more then 3 lines.
Any idea whats wrong?
Read From Specific Line In Text File
How can I read and write to a specific line in a textfile.
Say I want to write a string to say line 5 into info.txt and later I want read line 5 from info.txt
thanks Vidar
Read Only Last Line Of Text/ascii File
Hi Guys,
I needed some help regarding file reading in VB 6. I am writing a program that needs to insert a record in a text file. The text file has following format..
Date, Time, Open Price, Close price
Now i need to insert record only if date is greater than last date in file.
So everytime I need to insert record, I have to open file and read sequentially and then I reach last record. This takes time.
IS there a way to read such file in binary or whatever so that i can get last record straight away or very quickly without going thru all records one by one.
If there is can anyone post a small code.
[Records in the (text) file is like -
01/01/2006, 1100, 123.33, 155.55
01/01/2006, 1130, 122.22, 134.33
01/01/2006, 1200, 112.22, 124.33
so on ... ]
Thanks a lot,
Cheers,
GR
How To Read The Last Line Of A Text File Without Looping From The Begining
I like to check the last line of the text file before adding new data to the text file. This is required to avoid duplicate data.
Is there any way to read the last line without looping through the whole text file? Or, is it possible to loop from the last line of the text to the first line i.e. reverse direction?
Appreciate, your help.
Thanks.
Thiru
Read A Random Line From A Text File Separated By A %
How can i load a random line from a text file wich is separated by a %?
for example i have this text:
%
And 1.1.81 is officially BugFree(tm), so if you receive any bug-reports
on it, you know they are just evil lies."
(By Linus Torvalds, Linus.Torvalds@cs.helsinki.fi)
%
"...and scantily clad females, of course. Who cares if it's below zero
outside"
(By Linus Torvalds)
%
So the program will read a random line wich is between the %
Thanks in advance
Text File With 10 Lines, Want To Read And Display Only Second Line ... How?
Newbie question: I have a textfile (mytext.txt) containing 10 lines total: I have successfully coded how to read and display the first line OR all lines from the text file ... Next Step: How/What would I code to read and print say, only the second line?
Here's what I have:
Quote:
Option Explicit
Dim sampleoutput As String
Private Sub Command1_Click()
'Reads and displays first line from text file.
Open "C:My DocumentsPOS405dbtxtsamplemytext.txt" For Input As #1
Input #1, sampleoutput
Picture1.Print ""
Picture1.Print sampleoutput
Close #1
End Sub
Private Sub Command2_Click()
'Runs a loop to read and display all lines from text file.
Open "C:My DocumentsPOS405dbtxtsamplemytext.txt" For Input As #1
Do While Not EOF(1)
Input #1, sampleoutput
Picture1.Print sampleoutput
Loop
Close #1
End Sub
Private Sub Command3_Click()
'This code needs modification to read and display second line from text file.
Open "C:My DocumentsPOS405dbtxtsamplemytext.txt" For Input As #1
Input #1, sampleoutput
Picture1.Print ""
Picture1.Print sampleoutput
Close #1
End Sub
Thank you for any help.
~ Juanita
How To Read Multiple Line Text File Into A Variable
Hi,
I just found this site tonight. I've just started learning to program with Visual Basic and I'm having a very frustrating problem that I'm hoping someone here can help me with.
This post is a bit long. Sorry about that!
This has probably been asked many times before. My question is, how can you open a multiline text file and input EVERYTHING in the text file to a string variable? Basically, the text file will just be a list and the program will have to determine what items are on that list. I know how to open and save text files, and display text files in a textbox, but for some reason I can't figure out how to input an entire text file into a variable. It will only read the first line, and seems to ignore anything below the first line. I've been hunting on Google all night to try to find out about this, but with no luck.
Here's an example similar to what I need to do:
Let's say I have a text file named "List.txt" I have a command button that will add an item that the user chooses to this list.
Now let's say that the item the user chooses could be the string variable "new_item"
So I would have a command button with this code:
new_item=InputBox("What would you like to add to the list?")
Open "List.txt" For Append As #1
Print #1, new_item
Close #1
If we put in "a new car" for example in the input box, then this would be entered into the text file "List.txt."
Then let's click the command button again and put in "a boat" into the input box. It should then append the text file to read:
a new car
a boat
So far, so good. Now, let's say I have another string variable, named items_on_list. I also have another command button that will open the text file and determine what is on the list, with predetermined results if certain things are on the list. For example:
Open "List.txt" For Input As #1
items_on_list = Input(LOF(1), 1)
Close #1
What I WANT to do is this (again, just a generic example):
If items_on_list = "a new car" Then MsgBox("A new car, eh? Better save up!")
If items_on_list = "a new car a boat" Then MsgBox("Wow! A new car and a boat!")
But the problem I'm having is that the program would only read the first line and would ignore anything else. How can I open a text file and assign EVERYTHING, a multiline list in other words, to a string variable?
What I'm actually doing is working on a sort of strategy game that simulates a railway company. I know there are already dozens of games like this, such as Railroad Tycoon, etc. but this one will simulate a small railway company that was once in my area. I have a variable that I would like to use to keep track of specifically what locations the user has built lines to. Each time the user builds a new rail line, it would have to be appended to a list. There are certain instances, such as when a map is displayed showing all the rail lines, when this list would have to be opened and read into a variable, to determine which map to display in a picture box.
Again, I'm sorry for this post being so long! As you can tell, I'm still very new to all this. But this has been a very frustrating problem. I hope someone can help. Thank you!
Chris T.
San Bernardino, California
How To Read Data From Text File Tarting From Line 2
hey ya, this is my very first post
i would like to ask
how to read data from a text file starting in line 2.
i want to skip the first row. Start to read from 2 row
because the first line is string, i want to read only the integer
How Do I Read A SPECIFIC Line From A Text File ?? GURUS PLEASE HELP =)
A few easy questions for you gurus =)
1. How would I read a specific line from a textfile (for example line number 5)
2. How would i read a specific value in a text file? Lets say the file looks like an ini file:
thing1=value1
thing2=value2
How would i read/write from the specific value?? PLEASE HELP!!!!
Is it possible to search for a string in a file without loading it in a textbox? How would i then extract the value of thing2 for example then???
How Would I Read A Specific Line From A Text File As A String?
I would like to read configuration from a text file like config.txt
each line would look like: variable value (for example: version "0.9")
What code would i need to write if i only wanted to extract one variable and it's value from the config.txt?
How would i find the variable and read it's value ????
---------------------
~:{Decayed}:~
the.decayed@usa.net
http://www.q3seek.com
How To Read Text And Use It Line By Line
Hallo everyone,
I need help if its not so hard.
I am in a challenge site and one mission is to make a brute forcer
for a page like this www.site.com/../../../password=
I need a part of this project
So...
1) how can i make a button to read a .txt file and pass it into a listbox or anything else (excel or sth i dont know) in the form?
And after that
2) how can i make the program read the listbox line by line?
Thanks in advance for your time.
Greets
Read File: Search For Text If Found Delete Line
Hello Guys,
Need a bit help here...
I need to be able to read a file and search for a certain word.
If it exists, then delete whole line.
Ive tried it with the FSO method, but keep on getting 'System Variable with Block variable not set'
Is there another way to do this with the vb method of OPEN fNum ?
Thanx in advance
|