Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
Posted
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.
Posted

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=-

Whatever thy hand findest to do, do it with all thy heart - Jesus
Posted

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?

Posted

Lol, actually its a Navy Seal holding a gun. Its from a game called Counter-Strike. I just made him change colors =p

 

-=Simcoder=-

Whatever thy hand findest to do, do it with all thy heart - Jesus
Posted

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?

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...