How do you delete a specific line in a text file?

In VB6, how would you delete a specific line in a text file? I have emails loaded into a combobox that pulls its information from a text file. If the person selects the email, then presses the DELETE button, it should be removed from the text file. Is this possible?

Here's my code for pulling up the emails and placing them into the combobox
cboAccounts.Clear
            'See if any accounts are registered
            Dim sData As String
            Dim sArr() As String
            Dim i As Long
              'Set the global File name and path.
                m_File = App.Path & "\Accounts.txt"
              'Check if file exists.
                If Not LenB(Dir$(m_File)) Then
                    hFile = FreeFile()
                    Open m_File For Output As #hFile
                    Print #hFile, Form18.txtUsername.Text
                    Close #hFile
                ElseIf LenB(Dir$(m_File)) Then
                  'Get the data.
                    hFile = FreeFile()
                    Open m_File For Input As hFile
                      sData = input$(LOF(hFile), hFile)
                    Close hFile
            
                  'Move the data into the combo box.
                    sArr() = Split(sData, vbNewLine)
                    For i = 0 To UBound(sArr())
                    If sArr(1) <> Form18.txtUsername.Text Then Print hFile, Form18.txtUsername.Text
                    If sArr(i) <> "" Or Not sArr(i) <> vbNewLine Then Form18.cboAccounts.AddItem sArr(i)
                    Next i
                End If

Open in new window

Taylor814Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
unless the file has fixed-width records, you have to read the file, line by line, and rewrite it, skipping the line you want to delete.
no other way...
0
Taylor814Author Commented:
Ok, so how would I do that?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
something like this:
hFile = FreeFile()
                    Open m_File For Input As hFile
                      sData = input$(LOF(hFile), hFile)
                    Close hFile
            
                  'Move the data into the combo box.
                    sArr() = Split(sData, vbNewLine)
 
                    Open m_File For Output As hFile
                    For i = UBound(sArr) To UBound(sArr)
                      If sArr(i) <> Form18.yourcombobox.Text Then 
                         Print hFile, sArr(i)
                      End If
                    Next i
                    Close hFile

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.