473,624 Members | 2,539 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing to a text file.

I am logging things to a file but when I kill the app and
restart it, all the other logging is gone. How can I
prevent this form happening?
Nov 20 '05 #1
5 3151
* "Iceman" <an*******@disc ussions.microso ft.com> scripsit:
I am logging things to a file but when I kill the app and
restart it, all the other logging is gone. How can I
prevent this form happening?


.... by posting the code you use for writing the file.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #2
"Iceman" <an*******@disc ussions.microso ft.com> wrote...
I am logging things to a file but when I kill the app and
restart it, all the other logging is gone. How can I
prevent this form happening?


It sounds like your app is overwriting the file rather than appending to the
end of it.
Nov 20 '05 #3
Here you go...

Private Sub logchange(ByVal source As Object, ByVal e As
System.IO.FileS ystemEventArgs)

If e.ChangeType = IO.WatcherChang eTypes.Changed
Then

txt_folderactiv ity.Text &= vbCrLf & strUser
& " on " & strComputer & " - File " & e.FullPath & _
" has been modified - " & Now()

SaveTextToFile
(txt_folderacti vity.Text, "c:\Log.txt ")

End If

If e.ChangeType = IO.WatcherChang eTypes.Created
Then

txt_folderactiv ity.Text &= vbCrLf & strUser
& " on " & strComputer & " - File " & e.FullPath & _
" has been created - " & Now()

SaveTextToFile
(txt_folderacti vity.Text, "c:\Log.txt ")

End If

If e.ChangeType = IO.WatcherChang eTypes.Deleted
Then

txt_folderactiv ity.Text &= vbCrLf & strUser
& " on " & strComputer & " - File " & e.FullPath & _
" has been deleted - " & Now()

SaveTextToFile
(txt_folderacti vity.Text, "c:\Log.txt ")

End If

End Sub

Public Sub logrename(ByVal source As Object, ByVal e
As System.IO.Renam edEventArgs)

txt_folderactiv ity.Text &= vbCrLf & strUser & "
on " & strComputer & " - File " & e.OldName & _
" has been renamed to " & e.Name & vbCrLf

SaveTextToFile
(txt_folderacti vity.Text, "c:\Log.txt ")

End Sub

-----Original Message-----
* "Iceman" <an*******@disc ussions.microso ft.com> scripsit:
I am logging things to a file but when I kill the app and restart it, all the other logging is gone. How can I
prevent this form happening?


.... by posting the code you use for writing the file.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
.

Nov 20 '05 #4
"Iceman" <an*******@disc ussions.microso ft.com> schrieb
I am logging things to a file but when I kill the app and
restart it, all the other logging is gone. How can I
prevent this form happening?


Open the file in the Append mode.

If you use Microsoft.Visua lBasic.FileSyst em.FileOpen, pass OpenMode.Append
as the 3rd argument.

If you create a System.IO.FileS tream object, use System.IO.FileM ode.Append
as the file mode.

In addition, each time you write to the file, you should open the file,
write, and close it. If you don't close it after writing, some information
might be lost when the application is killed.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #5
* "Iceman" <an*******@disc ussions.microso ft.com> scripsit:
SaveTextToFile
(txt_folderacti vity.Text, "c:\Log.txt ")


Please post the code of the 'SaveToFile' method!

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
4595
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
2
3762
by: sp | last post by:
Hello everybody, I have an xml doc and I am trying to write the values from xml file to a tab delimited text file. Currently, what I am doing is I am reading xml file through XpathNavigaotr and manipulating all the nodes,elements and attributes than I am writing those values to a text file using stream writer. Now coming to my problem When I am writing data to the text file value of the last record is getting truncated. My code sample...
2
6850
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to replace just one item. I know I can get the entire array, then save the whole thing (with a for loop and if statements so that the changed data will be saved), but it seems like a lot of unnecessary reading and writing. Is there a way to directly save...
3
10328
by: CsharpNewcommer | last post by:
Hi Can someone tell me how to write the data from a TextBox (txt) or Label (lbl) to a text file to be printed. I have read the info from msdn.microsoft.com/library on "Writing Text to a File", and it only offers a solution for writing a text string and the system date. Help!!!!! I'm at a lost! Thanks
2
4481
by: Tony | last post by:
Yes, I need to specify a font type so that the characters will be evenly spaced when I write to a tab delimited text file. So how does one specify a font type to write/print and which font is best for evenness?
0
1710
by: Yunus's Group | last post by:
Yunus's Group May 23, 3:36 pm show options Newsgroups: microsoft.public.dotnet.languages.vb From: "Yunus's Group" <yunusasm...@gmail.com> - Find messages by this author Date: 23 May 2005 12:36:14 -0700 Local: Mon,May 23 2005 3:36 pm Subject: Writing to text file Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse
3
18958
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its original form. The problem is tha the binary source that I extract from the text file seems to be diferent from the source I saved. Here is my code: 1) handle=file('image.gif','rb')
3
3111
by: sethuganesh | last post by:
hi, i am not able to write a text properly in a text file in vb.net.below is the code that i have written. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim counter As Integer FileOpen(1, "c:\sample.txt", OpenMode.Random, , , 50) For Counter = 1 To 5
5
6194
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now is as follows: - i am trying to write code that will take any number of text inputs (names of other text files) and put them into a file line-by-line at the users request. meaning, i want the user to be able to type the strings and enter them...
6
5259
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
0
8246
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8490
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.