Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Saving to text code


  • Please log in to reply
3 replies to this topic

#1 TH0RN

TH0RN

  • Members
  • 28 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 PM

Posted 14 October 2008 - 03:23 AM

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?

BC AdBot (Login to Remove)

 


#2 Keithuk

Keithuk

  • Members
  • 960 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:03:55 AM

Posted 14 October 2008 - 07:15 AM

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?


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 :thumbsup:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#3 TH0RN

TH0RN
  • Topic Starter

  • Members
  • 28 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 PM

Posted 16 October 2008 - 03:08 AM

Thanks :thumbsup:

#4 Keithuk

Keithuk

  • Members
  • 960 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:03:55 AM

Posted 17 October 2008 - 06:11 AM

Thanks :thumbsup:


Ok so where was the fault? :flowers:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users