Results 1 to 6 of 6

Thread: How do I restore a file?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    65

    How do I restore a file?

    Hi, I am putting a text file in a listbox. But someone on here told me to restore the file. I dont know how to do this. Can someone help me. This is what I have:

    Open "c:/student docs/payroll.txt" For Input As #1
    Do
    Line Input #1, strLine
    intPos = InStrRev(strLine, Space(1))
    lstEmployees.AddItem Left(strLine, intPos - 1)
    intPos = InStr(1, Left(strLine, intPos - 1), Space(1))
    txtFirstName.Text = UCase(Left(strLine, 1) & Mid(strLine, intPos + 1, 1))
    txtLastName.Text = Mid(strLine, Pos + 1)
    Loop Until EOF(1)
    Close #1

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Go to a DOS window. Enter:
    Type c:/student docs/payroll.txt

    Is anythng in the file??
    If there is anything useful there, then you don't need to restore the file.
    If the file is empty (as we expect it will be), then you need to put something useful in the file.
    Either re-enter all the details using Notepad; or find out what created the file in the first place, and re-create it.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub cmdRestore_Click()
    2. Dim i As Long
    3. 'delete the old file
    4. Kill "c:\student docs\payroll.txt"
    5. 'open a new one
    6. Open "c:\student docs\payroll.txt" For OutPut As #1
    7.    For i = 0 To lstEmployess.ListCount - 1
    8.      lstEmployees.Selected(i) = True
    9.      Print #1, lstEmployees.List(lstEmployees.ListIndex)
    10.    Next
    11. Close #1
    12. End Sub

  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    If you open it for output, the contents will automatically be erased.

  5. #5
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160
    You knew that opening a text file for Output would erase its current contents, right Hack?

    So, why the Kill before the Open?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Yes, I know that opening a file for Output will erase the contents of the file.

    I know that using Kill to delete the file before issuing the Open is not necessary, however, it is a personal preference of mine.

    Who among us has not seen something happen, or not happen, that was supposed to happen? I like to leave nothing to chance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width