ljs235 Posted August 13, 2003 Posted August 13, 2003 I am creating a simple program composed on one windows form. The user will navigate the system through a series of buttons. What I'm having problems with is creating a log of the user's actions. I would like to create a text file that says when they click each button. I tried something like this: Dim sw As IO.StreamWriter = IO.File.CreateText("user_input.txt") sw.WriteLine("ButtonA: " & TimeOfDay) sw.Close() However, each time it did this, the text file would clear and only the most recent button clicked would appear on the text file. I've also tried using appendtext, but I get the same problem. Is what I'm trying to do even possible? Thanks in advance for your help. :) Quote
*Experts* Volte Posted August 13, 2003 *Experts* Posted August 13, 2003 Try using IO.File.OpenTextinstead. Quote
Diablicolic Posted August 13, 2003 Posted August 13, 2003 Dim sw As IO.StreamWriter = IO.File.CreateText("user_input.txt") sw.WriteLine("ButtonA: " & TimeOfDay) sw.Close() I had the SAME exact problem a few days ago. Here I'll get out my project real quick: At the top of the form (after the windows form generated code) enter this: Private LogWriter As New System.IO.StreamWriter(Application.StartupPath & "/Log.txt", True) This will open the stream to your Log file that's in the same directory as your application. The TRUE in that part, is so that when you write onto Log.txt, you don't write over what's currently in the file. Now when you want to write something into Log.txt, go like this: 'This creates a new line LogWriter.WriteLine(System.Environment.NewLine) LogWriter.WriteLine("User enters Button A") LogWriter.Flush 'The flush makes sure that the file gets written The stream will be open during the whole program time, at which could be bad, I don't know...but what I did, was close the stream during the OnClose event. Quote "Reality is fake, Dreams are for real"
ljs235 Posted August 13, 2003 Author Posted August 13, 2003 Thank you both for your help. I was able to solve the problem using your methods. You've saved me hours of unneeded headaches and I really appreciate it! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.