I am trying to read in one line of a text file at a time, basically, the text file will be full of numbers, but i want to read in one line at a time and display it in a text box, i can read in a full text file in one go but i dont know how to read in one line at a time, here is the code that reads in the whole text file, any help would be great, thanks....
'code:
Dim line As String
Open Filename For Input As #1
Do While Not EOF(1)
Input #1, line
Text1.Text = Text1.Text & vbCrLf & line
DoEvents
Loop
Close #1
I must be missing something (???) If you lose the loop, you can input a line. Is that what you want? (ps - you do realize that you share your name with one of the most famous Canadians ever )
"Knowledge is gained when different people look at the same information in different ways"
i have tried what you suggested but it simply pulls in the entire text of the file when i click on my import button, i cant get it to jsut simply read in one line at a time
i.e if the text files looks like this:
245
547
874
854
...etc etc....
when i click on import i want my text box to look like:
245
then when i cick the import button again i want the text box to look like:
245
547
and so on untill all lines have been read in, is this possible?
I played around with a test project - it is attached...hope it helps (it does import one line at a time)....Paul Henderson scored the winning goal in the first series between Canada and Russia in 1972....as for his or your looks, I honestly cannot say
"Knowledge is gained when different people look at the same information in different ways"
cheers mate thats great, just one question, i know i sound thick right now but how do i make it so that the programme can choose which text file it imports??? i have included what i have done so far, this one lets u choose while text file but how do i merge ur code and my code together!!!!
I read this post and find it is useful. However, I experienced that if the text file contains commas, it will be omitted while displaying in the textbox. Any comments and idea? Thanks
If the comma is part of the string it will be displayed. If you use it as a delimiter as I did in my example and split the string into an array, then it will be stripped.
cheers mate i will give it a go, is there any way it can be simply modified to allow you to choose which text fileu want to use, ie a file open button?
I'll be honest - I have not used the input statement since school....my work rarely involves the use of flat files...just did a quick check and yeah the delimiter for the input statement is a comma by default. I suppose you could read the file in and use replace function to clean it up if worst came to worst, but the advantage is it allows you to read in fields using multiple variables:
Code:
Input #iFileNum, strField1, strField2, strField3
If the file above had three fields separated by commas, you could read each line into its respective variable. But since henderson's need is only one column, it should still work out for him.
"Knowledge is gained when different people look at the same information in different ways"
cheers you guys have been great, ill give u a bit of backround as to why in need this and also why i am so confused. I hav e been given this assignment from a lecturer at uni, he wants us to read in a .wav file in text format, i used to think i knew a fair bit about computers music mp3's wav files and all that stuff, obviously not, i didnt know u could read in a .wav file as text, then he wants teh values in the text file, each line to be multiplied by 256 and add on the next line... still following, im not.... then these answers are displayed in another label or text box, presumably to give a list of values to form a spectrum analyser..... do any of you infinetley beings have a clue what im talking about????