I am trying to make an application that can look through directories and save certain files as favorites. The problem is that every time I change the favourite file, it says that it is a bad file, or that it is already open.
This is the code that i already have.
Private Sub cmd10_Click()
Open App.Path & ("\Choice10.Txt") For Output As #1
Write #1, txtAdd.Text
Close #1
Open App.Path & ("\Choice010.Txt") For Output As #1
Write #1, txtaddcaption.Text
Close #1
Open App.Path & "\Choice10.txt" For Input As #1
Input #1, ch10
Close #1
Open App.Path & "\Choice010.txt" For Input As #1
Input #1, ch010
Close #1
End Sub
what should I do to fix this?
Page 1 of 1
Saving to text code
#2
Posted 14 October 2008 - 07:15 AM
TH0RN, on Oct 14 2008, 09:23 AM, said:
I am trying to make an application that can look through directories and save certain files as favorites. The problem is that every time I change the favourite file, it says that it is a bad file, or that it is already open.
This is the code that i already have.
Private Sub cmd10_Click()
Open App.Path & ("\Choice10.Txt") For Output As #1
Write #1, txtAdd.Text
Close #1
Open App.Path & ("\Choice010.Txt") For Output As #1
Write #1, txtaddcaption.Text
Close #1
Open App.Path & "\Choice10.txt" For Input As #1
Input #1, ch10
Close #1
Open App.Path & "\Choice010.txt" For Input As #1
Input #1, ch010
Close #1
End Sub
what should I do to fix this?
This is the code that i already have.
Private Sub cmd10_Click()
Open App.Path & ("\Choice10.Txt") For Output As #1
Write #1, txtAdd.Text
Close #1
Open App.Path & ("\Choice010.Txt") For Output As #1
Write #1, txtaddcaption.Text
Close #1
Open App.Path & "\Choice10.txt" For Input As #1
Input #1, ch10
Close #1
Open App.Path & "\Choice010.txt" For Input As #1
Input #1, ch010
Close #1
End Sub
what should I do to fix this?
Open App.Path & ("\Choice10.Txt") For Output As #1
You don't need the () around the filename but the last two files you haven't used them. The file shouldn't be already open because your using Close #1 after you write to the file unless another part of your app as them open. Looking at that code apart from the brackets it looks ok. This must mean you have these files open somewhere else in your app thats why you get the bad file or the file is already open.
What you could use when you write to multiple files is
Dim FileNum As Integer
FileNum = Freefile()
'Freefile atticates the next available number to FileNum variable so they are being used by another process.
Open App.Path & "\Choice010.txt" For Input As #FileNum
Input #FileNum, ch010
Close #FileNum
Are all these files being written to in one Command button press? If you want to make sure that all open files are closed just use Close that will close all files that your app has open before you try to open another one.
Now the other problem you are to have with this is when you write text to the file it will overwrite the text thats already in that file. If you want to add the text to the end of that file then use Append.
Open App.Path & "\Choice10.Txt" For Append As #FileNum
Keith
Martin2k
Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows Vista Home Premium SP2 (laptop computer)
Martin2k
Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows Vista Home Premium SP2 (laptop computer)
Share this topic:
Page 1 of 1

Help


Back to top








