Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Read File, Just First Line?


hey,

im reading a file with


Code:


FileContent = Input$(LOF(hfile), hfile)



how can i just read the first line of the file instead of it returning every single line?

thanks

digi




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

Read File Line By Line, Populate Listbox
How can I read a text file line by line, and for each line, make a new row in the listbox?

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!

Faster To Read Line By Line, Or Whole File And Then Process?
Which is faster: Opening a file line by line... or creating a dynamic arr() and get the whole file, split at new line, and put it into the array, then use the array?

How Can I Read Only One Line Or Specific Line Of A Text File
How can i read only one line or specific line of a text file?

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

How To Read Text File Line By Line ?
I want to read Text File line by line until EOF. How can I do it?

Read A Text File Line-By-Line
I have a text file, and I want to read each line at a time.

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!!

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.

Read Text File Line By Line Through VB
Dear

I want to Read Text file through Vb.

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 A File Line By Line
Hi,

I am making a program to read from a file and write to another. I have done following:

--------------------------------------------
Dim strRead As String

Open "abc.txt" For Input As #1
Open "abcen.enc" For Output As #2

Do While NOT EOF(1)
Input #1, strRead
Write #2, strRead
Loop

Close #2
Close #1
---------------------------------------------

But, it read only the first line of the source file and writes it too. How will it come to next line till the EOF.

Read Txt File Line By Line
Have a txt file and i want to read line by line...
Only a prob. the dimension is 49 mb !!!!
EXistis a best way to read in very fast time?
HELP!

Read File Line By Line And...
I want the user to be able to write like http://www.google.com in one
textBox and Google in an other textBox.

Than I want the user to press a button when done. The text will then be past
like http://www.google.com,Google in to a file.

I want the user to be able to send as many links with names as they want to
that file. Then I want my program to be able to read from that file as I
start the program from a button at my form and use it in the program.

I am using MS Agent and I want the user to be able to write down links like
i described and then when I start the agent I want the agent to "build"
this:

All the names the user wrote:

Merlin.Commands.RemoveAll
Merlin.Commands.Add "Google", "Google", "Google"
Merlin.Commands.Add "Lunarstorm", "Lunarstorm", "Lunarstorm"
Merlin.Commands.Add "Back", "Back", "Back"
Merlin.Commands.Add "Forward", "Forward", "Forward"
Merlin.Commands.Add "Close", "Close", "Close"

The Names and the URL the user wrote down:

Select Case UserInput.Name
Case "Google"
URL= "http://www.google.se"
objInternet.Navigate Adress
Case "Lunarstorm"
URL= "http://www.lunarstorm.se"
objInternet.Navigate Adress

Case "Back"
objInternet.Back
Case "Forward"
objInternet.Forward

Case "Close"
objInternet.Quit
End Select

I want to do something like this:

Read the file line by line split the line at the "," and pot the left and
right string in an array and then go to the next line and add that to the
array as well and so on.

Then I want to use it in the MS Agent as this, to be able to use the links:
(As the Link names is the odd numbers I will just write out the odd
numbers.)

for (i=1, i<= aryLength(aryLink[i]), i=+2)
{
Merlin.Commands.Add "aryLinks[i]", "aryLinks[i]", "aryLinks[i]"
}

Merlin.Commands.Add "Back", "Back", "Back"
Merlin.Commands.Add "Forward", "Forward", "Forward"
Merlin.Commands.Add "Close", "Close", "Close"


Then here it is a little harder, the Case Is the odd numbers in the Array
and the URL is the even numbers.

Select Case UserInput.Name

Case "Google"
URL= "http://www.google.se"
objInternet.Navigate URL
Case "Lunarstorm"
URL= "http://www.lunarstorm.se"
objInternet.Navigate URL

These are not taken from the file:
Case "Back"
objInternet.Back
Case "Forward"
objInternet.Forward
Case "Close"
objInternet.Quit
End Select

As you can see is this not a language that exist... I don't know how to do
it in VB 6 It is not the same as using PHP with mySQL...

I'm a newbe to VB and some other languages as well...So it's all a bit
confusing...

Plz show me in the right direction to get this to work :-)

Read A File Line By Line
What I need to know is, if I had a text file with the following:


Code:

Apples
Bananas
Peaches


How would I get the program to read the first line, put it in a string variable, ead the second line, place it in another string variable, and do the same for the third. I know howto read files, but notline by line.

Thanks!

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


 

Read Line Above Last From File
Hello,
I need to read the line above the last from a file.

here is the text file i need to read from:

Chileno/Denver: de donde
Joe dirt: hi guys
scarecrow: hey
stanley2: where is the armor
x

How can i read "stanley2: where is the armor"

Read Last Line Only Of Txt 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 Do I Read From Just Last Line Of File? (txt)
On my program, a user is only allowed to do a certain amount of tasks per 24 hours. I have set the task number in the registry. When the program loads, it reads the text file and sees if 24 hours has passed (or if it was yesterday) and then it'll reset the registry.

The textfile looks like this:

Code:
"6966969","Sent Request on 1/6/2006 at 3:30:13 PM"
"26660046","Sent Request on 1/6/2006 at 3:30:19 PM"
"44955616","Sent Request on 1/7/2006 at 3:31:18 PM"
Here's how I'm doing it.


Code:
Private Sub Form_Load()
Dim strArray() As String
Dim intFNum As Integer
i = GetSetting("Project1", "dailycount", "count", i)

intFNum = FreeFile
Open App.Path & "log" & username & ".txt" For Input As #intFNum

strArray = Split(Input(LOF(intFNum), intFNum), vbCrLf)
Dim v, S As String, li As String, oi As String, m As String, time As String
For Each v In strArray
If Len(v) Then
li = Mid(v, 2, InStr(v, ",") - 3)
m = Mid(v, InStr(v, ",") + 2): m = Left(m, Len(m) - 1)
oi = Mid(m, InStr(m, "on") + 3): oi = Left(oi, InStr(oi, "at") - 2)


If Date > oi Then
SaveSetting "Project1", "dailycount", "count", 0
Close #intFNum
'Exit Sub
End If
End If
'End If
Next
Close #intFNum
End Sub

As you can see, once it reads the first line of the text ("6966969","Sent Request on 1/6/2006 at 3:30:13 PM"), the first date it sees is 1/6/2006, then date is less than todays date and it'll reset the registry. However, it should just read from the last line because it's only the last entered date that really matters.

Read File, Only First Line
Hello, I need doing this.
First Check all value in List1(),
Open List1 value ' that list1 value = full_path_and_filename /=dir/b that value
open that List1(x) , read only first line,
function_check line1 any non0-9,A-Z,a-z chars
List2.Additem FunctionRemove_nonAZ09(line1)


but any idea to completed ?
please suggest!


Code:
Command1_Click()

While @LIST1_All_Item(x)

MYFILE = LIST1_All_Item(x)

OPEN MYFILE
read line1 value
CLOSED MYFILE

List2.Additem FunctionRemove_nonAZ09(line1)

Wend

End Sub

'//////////////////


FunctionRemove_nonAZ09 (ByVal line1 as string)

only keep 0-9,A-Z,a-z and [space] chars. Else Chars remove

End Function

Read The Last Line From A Txt File
Hi,
How can I read the last line from a text file once I opened the file via the syntax below?

open app.path & " ext.txt" for input as #1
<????>
close #1

Thanks,

PhiL

How Do I Read From Just Last Line Of File? (txt)
I have a text file that has this in it

"Test1","Test2"
"Test3","Test4"

How do I just read the last line ("Test3","Test4")? This doesn't work

strArray = Split(Input(EOF(intFNum), intFNum), vbCrLf)

How To Read Line From Txt File
Can any one tell me how can i detect new line character using vb ?

Read The Last Line In A Txt File
Hi,
How can I read the last line from a text file once I opened the file via the syntax below?

open app.path & " ext.txt" for input as #1
<????>
close #1

Thanks,

PhiL

Read First Line Of Txt File
Hii,

How do I read the first line of txt file. Anyone who can tell me how this is easily done? Also adding a line to an existing file, and maybe first checking if the file exist and if it doesn't then create it and add the line.

ThanX

How To Read In One Line Of A File
Can someone tell me the syntax to read in one line of a file?
Tks

Read Last Line Of Txt File
My prog reads info from external txt files, but i want it to read the last line only. VB standardly reads the first.
How should i handle this?

(the txt file contains a new line of information every day, and the program should read the last line)

Read Last Line From End Of A File
Hi there,

Can any guru tell me how to read lines from a text file in reverse order, ie. starting from the end of a file to the beginning?

I want to read last a few lines first from a text file and I couldn't acheived it by using Line Input # statement because it starts reading from the beginning of a file.

Thanks,

Huyeote

How To Read The Last Line First From A File???
Hi,

Is is possible to first read the last line in the file and then read from the first line thru last line - 1?

I need the info that is stored at the last line in the file and I need that before I get any data and do any other manipulation.

Thank you,

Regards,
Swati

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

[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

Help On How To Read Certain Line From File And Write Them After
Ok here is my problem :
I got a loggin script running and it writes all the information about a computer to a text file. Now I wanna be able to retrieve informations from that text file. To do so I know that the information will be on lines that begin with some specific word. So I wanna be able to find that word after that to check after all the white space what is wirtten there, or if possible to write down that line to another text file.

Here is an example :

The text file in question look like this :
PC information for Windows 9x/NT/2000/Me version 1.30
----------------------------------------------------------------
Computer: PKB4657623E
Processor: Pentium II 450MHz (L1 cash: 32.0 Kb, L2 cash: 512.0 Kb)
Bios:
Motherboard:
Memory: 256 Mb (261 688 Kb)
User: john.doe
Domain: IT
Workgroup:
Shares: t:
v:
Mapping: p: (\NCCM01cm)

So I would like to do a search on this file so that I can write the line with the computer name, the line with the user. the line withe the user, the two lines with the shares and the mapping line, all those line I want them to be written to another text file. Also if that would be possible to do in VBScript or in .Net if you don't think so.

How To Read A Specific Line From Txt File?
I wan't to read lats say, line 5 how can I do it?


BTW:
How can I know the end (number) of array?
Or how can I check if array1(3) is ok? (If it's exist)

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.

Ini File Line Read Help Needed
hey, im reading lines from an ini file and the front end code looks like this :
VB Code:
List1.AddItem ReadIniValue(App.Path & Stu, "Class1", "1")
where you see the class1 that is one of the sections and where you see "1" is where it is reading the line! i have 6 sections and 4 or more lines in each section! but i have an option called ALL and when i choose that its ment to read all the lines and sections of the ini file! but i dont no how to write the code for that and i dont want to type the code in for all the sections and lines! any ideas? cheers

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

Fastest Way To Read Last Line Of File
Hi,

I have a function that returns false if the line "Table Closed" appears at the END of the file, and true otherwise. There has to be a faster way than this....


VB Code:
Private Function IsTableOpen(sFilename As String) As Boolean    Dim filenum As Long    Dim sline As String    Dim i As Long    Dim sDestination As String        filenum = FreeFile        Open sFilename For Input As #filenum    Do While Not EOF(filenum)        Line Input #filenum, sline    Loop    Close #filenum        If InStr(sline, "Table Closed") Then        'Move this file into the hand history folder        IsTableOpen = False    Else        IsTableOpen = True    End IfEnd Function

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.

Sequential File- Read Last Line
Is it possible to skip all the data and only read the last line in the file? I need to see which of the 2 files contains more data so I can set the comparison of time to the longer file. 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!

Read A Random Line From A Text File
i need to open a random line of a text file and save it in a string varibale. how would i go about doing this?

thnx for any help
Matt

Copyright © 2005-08 www.BigResource.com, All rights reserved