Hi i have a vb project im getting a bit of trouble with.

this is how it should work

user input text in the textbox.
the input text will be count as single character each one by one
after been checked they will be writen to a text file but all in caps
if use input symbols, there is a look up table to turn that symbol in charater and then write it to the text file.
after all that are writen to the text file another part of the program will copy the text file to another location and delete the original one.
so here is my problem because the text file will be deleted i need a code that will create a text file each time the programme runs.

in my code i use

Dim myfile As StreamWriter
myfile = File.CreateText("path of the file\thetextfile.txt")
and after this line i have the codes to convert character to all caps and also symbol to insert into the text file

then i have the code to write the data to the text file

Dim objFileToWrite As StreamWriter
objFileToWrite = CreateObject("Scipting.FileSystemObject").OpenTextFile("path of the file\thetextfile.txt", 2, True)
each time i run the aplication when it reach the part to write to the text file the programme freezes or it return an error cannot write to file beacause it is in use by another program.

can anybody help me


You have already opened the file with variable "myfile", before closing that,
you cannot again open the same file...
You have to close that file and re-open... or open one more new file with diff name for writing
write all the data.. close and rename it with original path.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.