Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 [solved]Creating .txt file then writing to it.

View previous topic View next topic Go down 
AuthorMessage
Clone
Member
Member
Clone

Posts : 7
Join date : 2011-06-24

[solved]Creating .txt file then writing to it. Empty
PostSubject: [solved]Creating .txt file then writing to it.   [solved]Creating .txt file then writing to it. EmptySat Dec 10, 2011 5:04 am

Okay so I have been searching for the answer to this for ages and just can't seem to find it. All i want to do is create a text file then write "0" (zero) to it.

It is for a larger project but this is the code that I have been working with:

Public Class Loading
Dim Path As String = "C:\NAME.txt"

Private Sub FileCreate()
Dim file As System.IO.FileStream
file = System.IO.File.Create(Path)
My.Computer.FileSystem.WriteAllText(Path, "0", False)
MsgBox("File created")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists(Path) Then
MsgBox("File Exists")
Else
MsgBox("File Missing. Will create")
Call FileCreate()
End If
End Sub

End Class

It all seems to work fine until it tries to write "0" to the .txt file. It comes up with an error saying that the process cannot access the file because another process is using the that it just created! I have checked and the only process using it is the one above. Sorry if this is a really simple problem, I am only learning at the moment. As I mentioned I have been looking everywhere for a solution but I cannot seem to find anything. This is my first time posting a new thread so is there anything else I should or should have mentioned? Any help is appreciated.

Thanks in advance,


Last edited by Clone on Sat Dec 10, 2011 5:08 am; edited 1 time in total
Back to top Go down
Awesomeness
Member
Member
avatar

Posts : 2
Join date : 2011-07-01

[solved]Creating .txt file then writing to it. Empty
PostSubject: Re: [solved]Creating .txt file then writing to it.   [solved]Creating .txt file then writing to it. EmptySat Dec 10, 2011 5:05 am

the io.file.create creates + opens the file.
my.computer.filesystem.writealltext tries to open or create the file but fails because it's already open.

Code:

    Private Sub FileCreate()
        using sw as new io.streamwriter(path)
            sw.write("0")
        end using
        MsgBox("File created")
    End Sub
Back to top Go down
Zombiesh
Member
Member
Zombiesh

Posts : 3
Join date : 2011-07-01

[solved]Creating .txt file then writing to it. Empty
PostSubject: Re: [solved]Creating .txt file then writing to it.   [solved]Creating .txt file then writing to it. EmptySat Dec 10, 2011 5:05 am

Close the file...

Private Sub FileCreate()
Dim file As System.IO.FileStream
file = System.IO.File.Create(Path)
My.Computer.FileSystem.WriteAllText(Path, "0", False)
file.Close()
MsgBox("File created")
End Sub
Back to top Go down
toxicity
Member
Member
toxicity

Posts : 6
Join date : 2011-06-21

[solved]Creating .txt file then writing to it. Empty
PostSubject: Re: [solved]Creating .txt file then writing to it.   [solved]Creating .txt file then writing to it. EmptySat Dec 10, 2011 5:06 am

Zombiesh wrote:
Close the file...

Private Sub FileCreate()
Dim file As System.IO.FileStream
file = System.IO.File.Create(Path)
My.Computer.FileSystem.WriteAllText(Path, "0", False)
file.Close()
MsgBox("File created")
End Sub

the error is on the WriteAllText line
Back to top Go down
Clone
Member
Member
Clone

Posts : 7
Join date : 2011-06-24

[solved]Creating .txt file then writing to it. Empty
PostSubject: Re: [solved]Creating .txt file then writing to it.   [solved]Creating .txt file then writing to it. EmptySat Dec 10, 2011 5:07 am

toxicity wrote:


the error is on the WriteAllText line

Thank you very much, explanation was very clear and it worked so thank you again. Now that my problem is solved is there something I should do with this thread? Close it or something?
Back to top Go down
Monchise
Member
Member
Monchise

Posts : 1
Join date : 2011-07-01

[solved]Creating .txt file then writing to it. Empty
PostSubject: Re: [solved]Creating .txt file then writing to it.   [solved]Creating .txt file then writing to it. EmptySat Dec 10, 2011 5:07 am

Mark it as resolved by using the Thread Tools at the top of post 1
Back to top Go down
Sponsored content




[solved]Creating .txt file then writing to it. Empty
PostSubject: Re: [solved]Creating .txt file then writing to it.   [solved]Creating .txt file then writing to it. Empty

Back to top Go down
 

[solved]Creating .txt file then writing to it.

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Comparing two data files and writing to a diff file (Request help)
» C: Read from file and write to file
» [solved]My Windows Service Won't Start?
» PHP Tutorials: Creating a Guestbook
» Creating arcade/adding games to your forum

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: [solved]Creating .txt file then writing to it. Edit-trash Useless :: Trash-