Add text1.text into a .txt file
Hi guys,
Does anybody know how i can make it so that when a user writes some text in a text box and presses command1
then the text they entered will be added to a .txt file in the app directory and each item will be added on a new line.
For example if i type hello in text1
then it will add to a .txt file - hello
and then if i wrote goodbye it would add goodbye to the .txt file on a new line?
I hope this makes sense.
Thanks.
Jamie
Re: Add text1.text into a .txt file
Yes, Open the file for Append.
Re: Add text1.text into a .txt file
Thanks,
Could you explain to me how to go about doing this? I don't understand what too do!
Cheers
Jamie.
Re: Add text1.text into a .txt file
Re: Add text1.text into a .txt file
Code:
Dim iFileNo As Integer
Dim sFileText As String
Open App.Path & "\example.txt" For Append As #iFileNo
Print #iFileNo, text1.text
Close #iFileNo
Make sure that there is a text file called "example.txt" in with the application.
Re: Add text1.text into a .txt file
thanks for the reply gamer, How ever i am having an error.
Saying bad file or number.
it then highlights - Open App.path & "\example.txt" For Append As #iFileNo
I have defo put a .txt file in the app directory called example.txt
What else could cause it to do this?
Thanks in advance,
Jamie
Re: Add text1.text into a .txt file
oh yeah. i fogot. after Dim sFileText as String, do
iFileNo = FreeFile
Re: Add text1.text into a .txt file
Hi ya mate,
Sorry but at the moment it seems to be adding the things from the text boz that i add all on the same line in the .txt file.
Is there a way to make it so each time i press to command button it adds the textbox.text into the txt file but on a differant line?
Thanks.
Re: Add text1.text into a .txt file
It shouldn't do that with Append. Do you have Output instead?
Re: Add text1.text into a .txt file
The code that Gamemaster gave you in post #5 (with the small addition in post #7) works just fine. You obviously made no effort to try and join the two to make it work.
Re: Add text1.text into a .txt file
Hi Jamie,
After modification, can you post your code here so someone can help you...
Regards
Veena
Re: Add text1.text into a .txt file
'if you use that code your need is ok.
Private Sub save()
Dim cfn, cf, fs
cfn = adress ' you will write here adress like that: c:/test.txt
Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile cfn, True
Set cf = fs.OpenTextFile(cfn, 8, True)
cf.Write (Text1.Text)
cf.Close
End Sub