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




Remove Text File Lines


What's the best way to keep the 50 first lines of a text file and drop the rest of the text file ?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Remove Lines From Text File.
i have a text file with the following...
---------------------------------------------
Email=gmatteson@myemail.com
Account=my email account
Username=gmatteson
Password=mypassword
Server=mail.myemail.com
Port=110
Query=10
---------------------------------------------

the email - gmatteson@myemail.com gets populated in a listview box.

so when the user clicks on gmatteson@myemail.com in the listview and click REMOVE I want it to delete everything from the
email=gmatteson@myemail.com to query=10.

The code below deletes the email=gmatteson@myemail.com, what i need is for it to delete the next 6 lines..... so that whenever a user deletes an email address it also deletes the information pertaining to that address..., does anyone know how to do this?

---------------------------------------------
Dim objFSO As New FileSystemObject
Dim objFile As File
Dim objTS As TextStream
Dim strReadLine As String
Dim strFind As String
Dim strData As String
Dim strEmail As String
Dim blnFound As Boolean

Dim strReadAll As String
Dim strELen As Integer
Dim strSLen As String
Dim strNewReadAll As String
Dim strWriteNString As String

Set objFile = objFSO.GetFile(App.Path & "pop3a.txt")

Set objTS = objFile.OpenAsTextStream(ForReading)
Do Until objTS.AtEndOfStream Or blnFound = True
'reads line in file
strReadLine = objTS.ReadLine
strFind = "="
strData = (InStr(1, strReadLine, strFind) + 1)
strEmail = Mid(strReadLine, strData)

If strEmail = lvwAccounts.ListItems(strSelected).Text Then
blnFound = True
End If
Loop
objTS.Close

Set objTS = objFile.OpenAsTextStream(ForReading)
Do Until objTS.AtEndOfStream
strReadAll = objTS.ReadAll
strELen = Len(strReadLine)
strSLen = InStr(1, strReadAll, strReadLine)
strNewReadAll = Mid(strReadAll, strSLen, strELen)
Loop

strWriteNString = Replace(strReadAll, strNewReadAll, "")
Debug.Print strWriteNString
objTS.Close
End If
-----------------------------------------

the strWriteNString is the string of the whole file that doesn't include the email that the user deleted, i would also like the user to be able to delete the info regarding that email, as explained above...
Thanks for any help,
- gabe

Remove Empty Lines From Text File
How can I remove all the empty lines from a text file?



Edited by - TankMaster on 2/21/2004 7:38:04 AM

How Can I Remove Duplicate Lines In A Text File?
I have made a function that removes duplicate lines in a text file but it does not always work here it is:


option Explicit

public Function RemoveDuplicateLines(FileName as string) as Integer

Open FileName for input Access Read as #1
Open App.Path & "integrity.tmp" for Output as #2

Dim LineIn(1 to 2) as string
Dim Impurities as Integer
Dim FirstPass as Boolean
Dim Last as Integer

FirstPass = true

Do
If EOF(1) = true then GoTo endof
'If it's the first time input 2 lines and compare them
'otherwise compare the last line with the next line
If FirstPass = true then

Line input #1, LineIn(1)
Last = 1

If EOF(1) = true then print #2, LineIn(1): GoTo endof

Line input #1, LineIn(2)
Last = 2

If EOF(1) = true then print #2, LineIn(2): GoTo endof

'Compare the lines
If LineIn(1) = LineIn(2) then

print #2, LineIn(1)

'Increment the defects
Impurities = Impurities + 1

else

print #2, LineIn(1)
print #2, LineIn(2)

End If

else 'It's not the first pass

If Last = 1 then

Line input #1, LineIn(2)
If EOF(1) = true then print #2, LineIn(2): GoTo endof

'Compare Line(1) with Line(2)

If LineIn(2) = LineIn(1) then
Impurities = Impurities + 1
print #2, LineIn(1)
else

print #2, LineIn(1)
print #2, LineIn(2)

End If

Last = 2

ElseIf Last = 2 then

Line input #1, LineIn(1)
If EOF(1) = true then print #2, LineIn(1): GoTo endof
'Compare Line(2) with Line(1)

If LineIn(1) = LineIn(2) then
Impurities = Impurities + 1
print #2, LineIn(2)
else

print #2, LineIn(2)
print #2, LineIn(1)

End If

Last = 1

End If

End If

Loop

endof:

Close #1
Close #2

Kill FileName
FileCopy App.Path & "integrity.tmp", FileName
Kill App.Path & "integrity.tmp"

RemoveDuplicateLines = Impurities

End Function





The problem with it is that it does two lines at a time so if my file is like this:

a
b
c
d
d
e
f

Then my output is like this:

a
b
c
d
d
e
f

Because 'd' was not reconized as a duplicate line. However if the file looked like this:

a
b
c
c
d
e
f

Then it would work because 'c' is an odd number.

My code looks complex because I though that it would work like this:

a <-- check this line with next line
b <-- check this line with next line
b <-- check this line with next line
c <-- etc..
d
e
f

But my code does this:

a <---\___ Check these two lines
b <---/
b <---\___ Check these two lines
c <---/
d
e
f


Can someone help me out??? Please!!

Remove Text Box Lines
I got text loaded into a text box, but need to remove the first 2 lines. Can anyone please tell me?

Thanks in advance

Remove Empty Lines From Text
Hi all,

I'm getting a data from a WebBrowser control, The data might look something like this (E.g. For Google.com):


Quote:





Web Images Video News Maps more »Blogs
Books
Products
Groups
Patents
Scholar
even more »

Advanced Search
Preferences
Language Tools



Advertising Programs - Business Solutions - About Google - Go to Google Jordan
©2007 Google


Get a Google-enhanced search box






My Question is how can I remove all these empty lines and make it as a paragraph (As a string) like this for example:


Quote:




Web Images Video News Maps more »Blogs Books Products Groups Patents Scholar even more » Advanced Search Preferences Language Tools Advertising Programs - Business Solutions - About Google - Go to Google Jordan ©2007 Google Get a Google-enhanced search box






Thanks very much,
zeid

Remove All The Lines Of Text Wich Doesn’t Contain A Word .
Hello .

For my second thread ,I need to remove all the lines of text wich doesn’t contain a word .
Or I want to keep the lines wich contains a definite word and to remove all the other lines
How to do ? Would you be able to give me any ideas ?

Example I want to keep the lines wich contains AABB
1/You can download all the tuts off this page
2/On this page, we got the tuts about the basics of what we should know.
3/first, get your tools....AABB(Just Links)
4/Then info on some tools and how to set them up and use them:
Only this line will stay
3/first, get your tools....AABB(Just Links)
because she contains the occurrence AABB
1/2/4/ this lines will have to be remove

Remove All The Blank Lines From A File
how would i open a file and remove all the blank lines ie. "" and save it again?


thanks :-)

Open A Text File And Count The Lines In Text File
Does anybody have any good vb code that would allow me to open a file count the lines in the file (or search for a certain character and do a count of that character) close the file and then compare it to a variable count. if the count is the same then continue, if the file is not the same delete the file and exit or abort the program.

example the lines I need to count start with 100000.

So i have a count of what is being pulled from the database of 60. I want to see if a file exists, if the file exists I want to do a count of all the lines starting with 100000. and compare it to 60 if the count is = 60 then finish, if it is not 60 then error out.

thanks!!!!

Insert Multiple Lines Of Text Into An Email From A Text File
Hi All,

I am looking for a way to read multiple lines from a text file anything upto 100 and then insert those into the body of an email message.

I can send the email as I know how to do that it just the reading of the text and then puttiong it into the email that I have a problem with.

Any idea's,

Regards,

Oz

How To Edit Text Files Or How To Remove Comma On The Text File
Hi,
    I have a problem on how to edit the comma in the text file. I will upload the data from the text file but some fields in the text files contains comma. by the way the text file is tabulated or tab delimited.

Lines In Text File
I'm not sure if I should be posting this here but I figured someone here would know this.

Are the # of lines in a text file limited by memory space or a numeric value.

Thanks

Lines In A Text File
Im making a program for learning [Pronomen] for german words:

Der Baum
etc....

I want to display a label that says how many questions (lines) there are in the file #1 and then how can I add a limit to how many lines it can read in?

Can u give me some help please?

How Do I Add Lines To A Text File?
Hi guyz.

I wanted to add lines to a text file but what i do results to replacing the all the lines in the file. Plese help! Thanx!

Lines From A Text File
I need help with VB, I know almost nothing and I am trying to write a very simple program.
Heres the problem, I need to know how to get line 46 from a text file called "dat.txt". Thats my whole program... Please help me....

Lines In Text File
Can I just know some how the no of lines in a text file? It's aim is to set the max value for a progress bar while importing.Thanks in Advance

Lines In Text File
is there any simple way to get the number of lines in a text file?
i know i can loop until eof(1) = true but is the any other way?

Get # Of Lines In Text File
I create a text file using the File System Object and add lines to it by using this example:

txtkill.Write ("john sucks") ' Write a line.
txtkill.WriteBlankLines (1)
txtkill.Write ("real bad") ' Write a line.
txtkill.Close

I need to add to this file some lines from another text file, is there any easy way to count the number of lines in the text file?

# Of Lines In A Text File
How do I get the number of lines in a text file?

No Of Lines In Text File
Is there a function in VB to tell me how many lines is in a text file? I want to display an accurate progress bar while importing large text files. I've tried using a combination of LOF() and Loc(), but Loc doesn't return an appropriate value.

Thanx!!

[VB6] Remove Text From A File
I am attaching a text file that I need code to remove all of the text up to the word WRID and then save the file with the change.

Thanks in advance for your responses...

Add And Remove Text In File
How do I add text to a file with a button and remove the text that I added with another button?

Lets say I want to add the text HELLO to a file with button1 and with button2 I want to remove the text HELLO from the same file.
How do I do this?

Delete Lines From Text File
Hello,

Using VB6, I want to open a text file, search lines that contain a specified string & delete the line if the string is found. Main problem is, I do not know what command to use to delete the line. Help is very much appreciated.


Regards,
Me

How To Read Different Lines Of A Text File?
I'm sure this is an easy enough question to answer but I wasn't able to find any threads about it so my apolgies if it has already been answered.

Basically what I need to do is read different lines of a text file depending on a random number for example on a number of 4 it will read line 4 of the text file. I am aware how to read the first line of a text file with

Open ("C: est.txt") For Input As 1
Line Input #1, strTest
Text1.Text = strTest
Close #1

however I am unaware on how to read any other lines.

Any help is greatly apprecitated thanks in advance

Write A Text (many Lines) In A File
Hi

I m facing a problem: if I write to a file, I need to do it line after line, if I copy paste a text, and do as follows, I can t even compile. How can I do?


Code:
Open BuildDirectory + "" + BuildName + ".html" For Output As #1
Write #1, "<html> _
<head/> _
<body> _
HELLO _
</body> _
</html>"

Close #1

thanks a lot

Number Of Lines In A Text File
is there any easy way of finding out how many lines a text file has in VB, ive know a very innefficient way, but would like to know what simpler means there is to achieve the same result:

Code:
Dim Subj ' just holds each line at a time
Dim SubjStr() As String ' the array which will be redimmed later to the right size..
Dim temp As String ' just a temporary thing..
Dim LineCount As Integer 'self explanatory
Dim n As Integer

Subj = FreeFile()

Open "I:ackupsMy DocumentsCollege StuffComputingVisual BasicNaminatorsubj.ini" For Input As #Subj
LineCount = -1
Do While Not EOF(Subj)
LineCount = LineCount + 1
Line Input #Subj, temp ' ***
Loop
Close #Subj

ReDim SubjStr(LineCount) ' make an array the size of the document...

Open "I:ackupsMy DocumentsCollege StuffComputingVisual BasicNaminatorsubj.ini" For Input As #Subj
For n = 0 To LineCount
Line Input #Subj, SubjStr(n)
Next n
Close #Subj

For n = 0 To LineCount
Print n & " " & SubjStr(n)
Next n
*** I would like to know if there is a way to reset this, as this always goes onto the next line right? this would mean i wouldnt have to close and open the txt file again..

the reason i cant just add the lines directly to the array is becuase i want the array to be the same size as the amount of lines in the document (which is not constant..)


ive only been doing VB for a month or two now, this is my first app that uses any kind of IO..

Overwriting The Lines In Text File
Hi There,

Below source code is creating the text file without problem. But it is overwriting the Data from above lines. Because the first Detail tables are having more field than the trailer table. Let me know how to avoid this???

Here is the code :

Function ExportFileToLoannet(sFileName As String)
'--
'Form Level Function
'Write data into a fixed length ASCII file
'--

Dim sSQL As String
Dim adoRS As ADODB.Recordset
Dim iCount As Long
Dim cmdCommand As ADODB.Command
Dim sOutputFile As String
Static bIsFileCreated As Boolean
Dim ifHandler As Integer
''Dim sFile As String * 250
Dim sCreateFileName As String
Dim Header As Variant
Dim X As String
On Error GoTo errExport
Me.MousePointer = vbHourglass


'--get a handler
ifHandler = FreeFile

'--get a filename
''sFileName = sGetFileNameLexis

sCreatedFileName = sFileName

'--create the file first
Open sFileName For Output As ifHandler
bIsFileCreated = True
'--Header Format


sSQL2 = "SELECT * FROM tbl_detail_96537"

Set adoRS2 = ExecuteSQL(sSQL2, sText, iSybase)

If adoRS2.BOF Or adoRS2.EOF Then
MsgBox "No Detail records found"
Me.MousePointer = vbNormal
Exit Function
End If

With adoRS2
Do While Not .EOF

Mid(sFile, 1, 1) = Trim$(.Fields![det965_record_type])
'--VENDOR NAME
Mid(sFile, 2, 5) = Trim$(.Fields![det965_client_id])
'--INVOICE_NUMBER
Mid(sFile, 6, 14) = Trim$(.Fields![det965_cusip])
'--INVOICE_DATE
Mid(sFile, 15, 18) = Trim$(.Fields![det965_routing_table_id])
'--INVOICE_AMOUNT
Mid(sFile, 19, 27) = Trim$(.Fields![det965_quantity])
'--APPROVED
Mid(sFile, 28, 28) = Trim$(.Fields![det965_collateral_code])
'--CHECK_DATE
Mid(sFile, 29, 48) = Trim$(.Fields![det965_comments])

Mid(sFile, 49, 53) = Format(.Fields![det965_min_rebate_rate], "#####")
'--VENDOR NAMEFormat(CStr(-CDbl(Mid(Data, 2, Len(Data) - 2))), "###,###,###,###,##0.00")
Mid(sFile, 54, 54) = Trim$(.Fields![det965_min_rebate_rate_code])
'--INVOICE_NUMBER
Mid(sFile, 55, 63) = Trim$(.Fields![det965_min_partial_quantity])
'--INVOICE_DATE
Mid(sFile, 64, 71) = Format(.Fields![det965_max_price], "########")
'--INVOICE_AMOUNT
Mid(sFile, 72, 75) = Trim$(.Fields![det965_time_out])
'--APPROVED
Mid(sFile, 76, 76) = Trim$(.Fields![det965_loanet_indicator_code])
'--CHECK_DATE
Mid(sFile, 77, 77) = Trim$(.Fields![det965_batch_code])

Mid(sFile, 78, 78) = Trim$(.Fields![det965_profit_center])
'--VENDOR NAME
Mid(sFile, 79, 79) = Trim$(.Fields![det965_mark_parameter_type])
'--INVOICE_NUMBER
Mid(sFile, 80, 81) = Trim$(.Fields![det965_mark_parameter_amount])
'--INVOICE_DATE
Mid(sFile, 82, 82) = Trim$(.Fields![det965_tracking_indicator])
'--INVOICE_AMOUNT
Mid(sFile, 83, 88) = Format(.Fields![det965_dividend_flow_thru], "######")
'--APPROVED
Mid(sFile, 89, 100) = Trim$(.Fields![det965_blank])
Print #ifHandler, sFile
.MoveNext

Loop
End With

sSQL3 = "SELECT * FROM tbl_trailer_96537"

Set adoRS3 = ExecuteSQL(sSQL3, sText, iSybase)

If adoRS3.BOF Or adoRS3.EOF Then
MsgBox "No Trailer record found"
Me.MousePointer = vbNormal
Exit Function
End If
With adoRS3
Do While Not .EOF
'--CHECK_DATE
Mid(sFile, 1, 1) = Trim$(.Fields![tlr965_record_type])
Mid(sFile, 2, 6) = Trim$(.Fields![tlr965_count])
Mid(sFile, 7, 22) = Trim$(.Fields![tlr965_total_qty])
Mid(sFile, 23, 100) = Trim$(.Fields![hdr965_blank_2])
Print #ifHandler, sFile
.MoveNext
'''
'''''''' Mid(sFile, 125, 10) = Format(.Fields![PAY_AMOUNT], "######.00")

Loop
End With


Close 1
MsgBox _
Prompt:="File Created Successfully", _
Buttons:=vbOKOnly, _
Title:="Export"

Me.MousePointer = vbNormal
ShellAndLoop sBatchFileName, vbNormalFocus

Exit Function
errExport:
If bStopProcess Then
Close
Else
MsgBox Err.description, vbCritical
bStopProcess = True
Me.MousePointer = vbNormal

End If

End Function


Thanks
Ekta

Editing Lines In A Text File
Hello, I have a text file that looks like this:

335
00:30:55,689 --> 00:30:59,651
We are here to plead the case
of Edmond Dantes, Magistrate.

336
00:31:00,151 --> 00:31:01,736
Not now! Dantes?

337
00:31:01,736 --> 00:31:05,740
We have not met, monsieur.
I am Fernand Mondego, the son of Count Mondego.


I would like to edit this file so that 335, 336, and 337 are changed to 1, 2, and 3, respectively. Can anyone help me with this? Thanks in advance.


Ayrie

Count Lines Of Text In Txt File
Is there any easy way of finding out how many lines of text there are in a specific Text File ?

Text File With Multiple Lines Help.
I got a .txt file, with multiple lines. I don't want to confuse you guys, so i'll give you an easy example of what I'm looking for.

I have a text file with this in it:

Hello this is line 1
and this is 2
this...is line 3

How would I read those lines one by one, or seperate them, becuase when I try to read it with input #filenum, variable , it only returns the first line in the .txt file...
I would appriciate some help :P ty

Loading The Last Few Lines Of A Text File.
Recently I created a utility that to be used on machines where little memory is left over due to memory intensive applications.

When I found I needed to load the last few lines of fairly large text files In this kind of environment I came up with this lightweight tool. It loads a user defined block of text from the end of the file. Then parses that into lines of text. For my needs that was about 1K.


Code:
Private Sub GetLastFewLines(ByRef LST As ListBox, ByVal sFileName As String, ByVal BufferSize As Integer, ByVal LineCount As Integer)
Dim FSize As Long
Dim sBuffer As String
Dim s() As String
Dim i As Integer
Dim bReadAll As Boolean

FSize = FileLen(sFileName)
If FSize <= (BufferSize * 2) Then bReadAll = True

Open sFileName For Binary As #1
If bReadAll Then
sBuffer = Space$(FSize)
Else
sBuffer = Space$(BufferSize)
Seek #1, (FSize - BufferSize)
End If
Get #1, , sBuffer
Close #1

If Right$(sBuffer, 2) = vbCrLf Then sBuffer = Left$(sBuffer, Len(sBuffer) - 2)
s = Split(sBuffer, vbCrLf)

If UBound(s) < LineCount Then LineCount = UBound(s) + 1

For i = UBound(s) - (LineCount - 1) To UBound(s)
LST.AddItem s(i)
Next i
End Sub

~T

Loading Lines From A Text File
Here is my problem: I can load the first line of a text file into my text box, but not the rest. How can I get every line of the text file to load in my text box?

Here is the code:

Code:
Private Sub Command2_Click()
Dim intFile As Integer
Dim str1 As String
Dim Path As String
intFile = FreeFile
Path = Dir1.Path & "" & File1.FileName
Open Path For Input As #intFile
Input #intFile, str1
Text1.Text = str1
Close #intFile
How can I get this to load ALL lines of the selected text document?

Count Lines In A Text File
hi,
Would there happen to be a way to count how many lines there are in a text file?

THanks

Delete Lines In A Text File
Hi to all,

I would like to delete lines in a text file only if the number of identical header lines is not a multiple of 2 and write the delete header in an another text file.

Here is how the file is :

Header1, m,s,r1

Header1, m1,s1,r1

Header1, m3,s3,r3

Header2, m2,s2,r2

Header2, m2,s2,r2

Header4, mz,se,re

Header4, mt,su,r2





---

The excepted output file is :

Header2, m2,s2,r2

Header2, m2,s2,r2

Header4, mz,se,re

Header4, mt,su,r2


Deleted header :

Header1

Deleted lines :

Header1, m,s,r1

Header1, m1,s1,r1

Header1, m3,s3,r3

Any idea?

Extracting Lines From A Text File :)
Hi,

I wonder if somebody could help me here. I have a text file 'Teams.txt' which contains the following:

Wolves vs Charlton Athletic
2
A
Monday
"12:00"
1
RCB
Week No
#2004-03-08#
Wolves vs Fulham
1
A
Monday
"12:00"
2
EHB
Week No
#2004-03-08#
... more teams here

The sequence is repeated after 9 entries, for each fixture. The fixture has information such as time, day, date pitch no etc associated with it. What I want to be able to do is (because there will always be 9 entries) extract the first entry for as many fixtures in the text file. So in effect, what I will end up with is:

Wolves vs Charlton Athletic
Wolves vs Fulham

I have supplied the code I am using to read the file but I've become a bit stuck and would appreciate any help on this matter.

Open App.Path + "Teams.txt" For Input As #1

Do While Not EOF(1)
Line Input #1, strLine

............

Loop

Close #1

Thanks a bunch guys,

MiniMe

Read First Ten Lines Of A Text File?
I have some code that currently reads the first line of a text file. I want to change this and have it read the first ten lines, is this possible?

Here is the current code (blatantly simple):

'Open File for Reading
Open workfile For Input As #1
'Read in first line of file
Line Input #1, strFilesText
Close #1

Thanks.

Delete Lines In A Text File
i start in vb and i'm not very good, but i've this code for delete a line in a text file, is it possible to delete some part of line?
for lines 100 to 200 for example?
thank you for all!!!

DeleteTextLine(App.Path & "sp11.txt",12)


Public Function DeleteTextLine(fName As String, linenumber As Long) As Boolean

Dim FSO As New FileSystemObject
Dim FSTR As Scripting.TextStream
Dim ret As Long
Dim lCtr As Long
Dim sTemp As String, sLine As String
Dim bLineFound As Boolean

On Error GoTo ErrorHandler
If FSO.FileExists(fName) Then
Set FSTR = FSO.OpenTextFile(fName)
lCtr = 1
Do While Not FSTR.AtEndOfStream
sLine = FSTR.ReadLine
If lCtr <> linenumber Then
sTemp = sTemp & sLine & vbCrLf
Else
bLineFound = True

End If
lCtr = lCtr + 1
Loop

FSTR.Close
Set FSTR = FSO.CreateTextFile(fName, True)
FSTR.Write sTemp

DeleteLine = bLineFound
End If


ErrorHandler:
On Error Resume Next
FSTR.Close
Set FSTR = Nothing
Set FSO = Nothing

End Function

Deleting Lines From Text File...
I have a text file with usernames and password in it. It looks like:

joe, schmoe
fred, blah
monkey, hater

How would i go about deleting the only fred account? So far, I have:

Open "contacts.fda" For Output As #intContacts

If cmdDelete.Value = True Then

Please help, thanks

Encrypting Lines In A Text File
How would i encrypt certain lines in a text file? And afterwards, decrypt the file for reading?
As in, for example:

File.txt

Code:
Blargh,5
blargfgd,12
fadskfd,7
Encrypted:
#$98ƒ≡3▲╖
98ƒ≡3$98ƒ
23497432

Something like that. Like a letter subsitution function?
And how would i decrypt something like that?
Thanks! (code is appreciated GREATLY)

Deleting Two Lines In A Text File
Thanks to All of you i have this code:

Dim Line As Integer
Dim LineStr As String
intpress = InputBox("Enter The Line Number Of The Member You Want To Delete.", "Delete Member")
If intpress = "" Then: Exit Sub
Close #1
Close #2
Open "C:windowsdesktoppersonnel.txt" For Input As #1
Open "C:windowsdesktoppersonnel1.txt" For Append As #2

Do While Not EOF(1)
Input #1, LineStr
Line = Line + 1
If (Line <> intpress) Then

Write #2, LineStr
Else
'Ignore the line
End If

Loop

Close #2
Close #1

Kill "c:windowsdesktoppersonnel.txt"
Name "C:windowsdesktoppersonnel1.txt" As "C:windowsdesktoppersonnel.txt"

This Works Great! but one more thing , the saved text that i have on my text file has two prts that needs to be deleted. this code will delete a specific line , but i need it to delete the line specified by the user in the inputbox and the line under it, say the user wants to delete line 1, i need it to delete line 1 and 2. any ideas , iv'e tried to works some code in but i always delets that one line and not the second.

Deleting Lines Of Text From .txt File
I want to have the user choose a line in a list box, and then click a button to delete it from the .txt file. So far i am able to make a string called deleteline that contains the text to be deleted. Now i just have to go through the text file, find that line, delete it, and have the text file result without any spaces(blank lines). Ask questions if you need more information.

Thanks for helping me.

Take Selected Lines From Text File
Hello All,

Can anyone please help me how to fetch the selected line from text files.

I have a text file and it contains 20 to 25 rows. All files have shuffled lines.
Name=2525152.TXT
Size=1086396
Job=2525152
Original Job=2525152
JOB Time=2/14/2008 10:27:06 AM
Length=288
ID=99915
Subject=
Location=23
Name=Work
Time=2/14/2008 10:27:06 AM
Type=9306
Code=1
Account=1
Department=0
User=0
User=0
User=0
User=0
Pending=0
Request=0

Now i need the following fields in seperate text file
Subject=
Name=
JOB Time=
type=
Department=
Account=

Calculating Lines From Big Text File
Hello I need some help.
I use this code to read and calculate total count of lines from big (~1GB) *.TXT files.
Code:

Code:
Private Sub Command1_Click()
Dim TotalCountOfLines As Long
TotalCountOfLines = 1

CountNextLine:
If Len(GetSpecificLine("C:1.txt", TotalCountOfLines, 65536)) > 0 Then
TotalCountOfLines = TotalCountOfLines + 1
GoTo CountNextLine
Else
MsgBox TotalCountOfLines
Exit Sub
End If
End Sub

Private Function GetSpecificLine(filename As String, ByRef LineNumber As Long, Optional BufferSize As Long = &H10000) As String
Dim FF As Integer, Buf() As Byte, LnCt As Long, Pos As Long, i As Long, SLn As Long, ELn As Long
'Linenumber is passed Byref and returns the file position of the line

If BufferSize < 1 Then Exit Function
ReDim Buf(BufferSize - 1)
LnCt = 1
Pos = 1
LineNumber = Abs(LineNumber) - 1
If LineNumber < 1 Then SLn = 1

FF = FreeFile
Open filename For Binary As #FF
For Pos = 1 To LOF(FF) Step BufferSize
Get #FF, Pos, Buf
For i = 0 To BufferSize - 1
If Buf(i) = 13 Then
LnCt = LnCt + 1
If LnCt > LineNumber Then
If SLn Then
ELn = Pos + i - 1
Exit For
Else
SLn = Pos + i + 2
End If
End If
End If
Next i
If i <> BufferSize Then Exit For 'The line has been found
Next Pos
If SLn Then
LineNumber = SLn
If ELn = 0 Then ELn = LOF(FF)
ReDim Buf(ELn - SLn)
Get #FF, SLn, Buf
GetSpecificLine = StrConv(Buf, vbUnicode)
End If
Close #FF
Exit Function
End Function


But there is problem because I'm geting incorrect count of lines. I think that problem is in this part of code:

Quote:




Private Sub Command1_Click()
Dim TotalCountOfLines As Long
TotalCountOfLines = 1

CountNextLine:
If Len(GetSpecificLine("C:1.txt", TotalCountOfLines, 65536)) > 0 Then
TotalCountOfLines = TotalCountOfLines + 1
GoTo CountNextLine
Else
MsgBox TotalCountOfLines
Exit Sub
End If
End Sub






So maybe someone can look at code and help me find there is inaccuracy.

Couting Lines In A Text File
Hello, please can you tell me or guide me how to go about coding an action that counts how many lines are in a text file?

Thankyou very much

How To Overrite Lines In A Text File?
let say i've input a few lines here:

VB Code:
...for i = 0 to 3   Print #iFileNo, item(i).textnext ...


later, if i wanna replace the second line with forceData.text, how can i do that?

Editing Particular Lines Of A Text File?
Let's say I have 3 lines in my text file.

Line 1
Line 2
Line 3


How would I go about replacing the line that says 'Line 2' with 'xxxxxxxxxxxxx' or something else, but leave the rest of the .txt file alone? I'm using visual basic 5 with the filesystemobject (by referencing scrrun.dll the VBScript expression(s) )

Please Help Me! Multiple Lines From A Text File
I have the following text file that i call messages.txt, and next i have the following code that i read that file. the problem is that i want to read the test1 from the "=" sign till "@" sign but i dont know how to do it. Please help me.


VAR1=5
VAR2=7

TEST1=afdsagadsgasdhsfdhsfghsfgh
sfghsfghsfghsfghfsg

sfghsfghfghfsghsfghfsgh
sfghfsghsfgh
sfghggh

sghsghsgfh@



Private Sub Form_Load()
Dim I, anystring As String
Dim start_text As String
Dim buffer As String

Free = FreeFile

Open App.Path & "messages.txt" For Input As #Free

Do While Not EOF(Free)
Line Input #Free, anystring
start_text = start_text & anystring & vbCrLf
RichTextBox1.TextRTF = start_text
'start_text = Trim(Right(anystring, Len(anystring) - InStr(anystring, "=")))

Loop

Close #Free

End Sub

Number Of Lines In A Text File
Im wondering if any of you guys have a function to count the total number of lines in a text file, e.g.

if C: est.txt has 3 lines then Text1.Text = "3"
otherwise if the file C: est.txt does not even exist then Text1.Text = "No such file"

Something like that? Any help would be greatly appreciated!

Loading Only The Last 4 Lines Of A Text File Into VB
Hello, any help will be appreciated

here is my small problem.

this is the code I'm using to load a certain text file into a Rich Text box.

Open FilePath For Input As #7
Do While Not EOF(7)
Line Input #7, Data
If Data <> "" Then RichTextBox1.Text = (RichTextBox1.Text & Data & vbCrLf)
Loop
Close #7


The code works fine but my problem is this. I don't want the whole file to be loaded. I only want the last 4 lines to be loaded into the rich textbox.

Thank you for any help!

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