How do I save text in a text box into a text file with a fixed name and a fixed directory? Like,

If 'event happens' Then

save everything in the textbox to a.txt to C:\bla\
Who is Participating?
AndySulzConnect With a Mentor Commented:
Use a Rich Text Box and a common dialog control


richtextbox1.savefile commondialog1.filename
suppose the 'event' is a button click. then you write the foll. in sub button1_click:

dim file_i as integer

file_i = freefile
open "C:\bla\a.txt"  for input as #file_i

print #file_i text1.text

close #file_i


that's all you need.
i maybe a little off the mark in syntax, as i am giving this off the cuff, but this is what you have to do.

I think you want to open the file for "Output" not input.  Also you need to separate the file number from the data with a comma:

Open "C:\bla\a.txt" For Output As #file_i

Print #file_i, text1.text
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

mrcool4444Author Commented: didn't work.  It said that the path for C:\bla\a.txt isn't found.  I changed the directory to C:\a.txt and it didn't work.  I even made a a.txt in C:\ and it still didn't work.  If you revise the code and post it as a answer and it works, then I will accept it, but this doesn't do what I need it to.  
i must have been asleep when i wrote that code: what Joe_Griffith says is right :-)

make the corrections, and that should do it.

check.... richtextbox1.savefile commondialog1.filename , 1
mrcool4444Author Commented:
Huh?  Do what now?  I don't understand, what is a rich text box, a common dialog control?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.