Text addition

murrayf1

Member
Joined
May 5, 2006
Messages
21
Programming Experience
1-3
Ok i have a file number.txt that by deafult contains the number 1. upon an even happening in my program i want to change this to 2 and then to 3 if the event occures again.

How can i do this.
 
If this is a file generated by your application, which it does sound like since you want to read/change/write back, then you should use the application settings instead to store this value.

About what you asked, is this all content there is in this file? What exactly is your problem with doing this series of operations? everything? You can start by learning how to read the file, for example documentation for my.computer.filesystem object http://msdn2.microsoft.com/en-us/library/microsoft.visualbasic.fileio.filesystem.aspx, or see the first posts of this thread for example http://www.vbdotnetforums.com/showthread.php?t=12782
If reading from a file is not the problem maybe you could be more specific at what tasks you don't know how to do?
 
Hi,

I know how to read from a file but i dont know how i can add "1" to the value so for example.

If the file contains "3" and my app does an even i want to change this value to 4, when it does the event again change it to 5 ect.
 
well, you get the "1" as text from file, so you have to convert it to a integer, this is convenient with TryParse. Because if you add "1" + "1" strings they concenate to "11", but if you add integer 1 + 1 they add as mathematical numbers to 2.
VB.NET:
Dim int As Integer = 0
If Integer.TryParse("1", int) = True Then
   int += 1
   MsgBox(int.ToString) 'let you see that int was read 1, added 1 = 2
End If
 
Back
Top