JDYoder Posted August 15, 2005 Posted August 15, 2005 I need to keep a log file of activity in a simple text file. I've done this in VB6, but I'm guessing VB.NET has a single object I can use to write individual lines to a text file. Or is that not the case? Thanks for any recommendations you can give. Quote
Administrators PlausiblyDamp Posted August 15, 2005 Administrators Posted August 15, 2005 You want to look at the classes in the System.IO namespace, specifically the FileStream and StreamWriter classes. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JDYoder Posted August 15, 2005 Author Posted August 15, 2005 If I declare variables as either of those types, I see there are "Write" commands and other stuff, but I'm not seeing how you assign a particular file to either of them to serve as the log file. Quote
Simcoder Posted August 15, 2005 Posted August 15, 2005 Not sure if this helps, but this is how I log stuff to text files. Dim Datawrite As StreamWriter Datawrite = New StreamWriter("C:/Test.txt") Datawrite.WriteLine("Hello World") Datawrite.Close() -=Simcoder=- Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
JDYoder Posted August 16, 2005 Author Posted August 16, 2005 That looks like it'll work. Thanks for the starting point. BTW, I can't figure out your avatar... what is it? Some mythical being playing a flute? Quote
Simcoder Posted August 16, 2005 Posted August 16, 2005 Lol, actually its a Navy Seal holding a gun. Its from a game called Counter-Strike. I just made him change colors =p -=Simcoder=- Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
JDYoder Posted August 16, 2005 Author Posted August 16, 2005 Ah. I can kind of see it now. hehe. Your code worked for me, but I see it always recreates the file. How can I tweak it so that it will append instead? Quote
thenerd Posted August 16, 2005 Posted August 16, 2005 dim fs as filestream fs = new filestream("C:\test.txt",filemode.append) dim sw as streamwriter sw = new streamwriter(fs) sw.writeline("Poo") sw.close fs.close That should do it. Check the intellisense when you type filemode. You'll get quite a few of options there. Also, streamreaders work very similarly to streamwriters. EDIT: Oh! filestream,streamwriter,streamreader and filemode are all things in the system.io namespace. So, they should be io.filestream, io.streamwriter, etc if you didn't import io. 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.