|
-
Oct 22nd, 2002, 09:34 PM
#1
Thread Starter
Lively Member
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
-
Oct 23rd, 2002, 03:44 AM
#2
Frenzied Member
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.
-
Oct 23rd, 2002, 12:50 PM
#3
VB Code:
Private Sub cmdRestore_Click()
Dim i As Long
'delete the old file
Kill "c:\student docs\payroll.txt"
'open a new one
Open "c:\student docs\payroll.txt" For OutPut As #1
For i = 0 To lstEmployess.ListCount - 1
lstEmployees.Selected(i) = True
Print #1, lstEmployees.List(lstEmployees.ListIndex)
Next
Close #1
End Sub
-
Oct 23rd, 2002, 01:14 PM
#4
Software Eng.
If you open it for output, the contents will automatically be erased.
-
Oct 23rd, 2002, 02:10 PM
#5
Frenzied Member
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.
-
Oct 23rd, 2002, 02:17 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|