I have a program that tells you how many times you have clicked a button. The problem is I want it to show that number of clicks when I close the program and then reopen it.
How do I do this?
Printable View
I have a program that tells you how many times you have clicked a button. The problem is I want it to show that number of clicks when I close the program and then reopen it.
How do I do this?
First declare a static variable that holds the number of clicks that will be add by each click on the button . Then , in the closing event put your code that write the value of this variable to file . In this load event , set back the value in the file to the static variable and keep adding to it by each click . Unfortunately , I'm not at my dev computer so I can't be sure about the snippet of code that I was going to give but if you still have problems , I will give you the code later .
This should start you off, I haven't tested it so it might be wrong...
VB Code:
Dim NumberOfClicks As Integer = 31 'the variable youwant to write Sub WriteNumber() 'to write text file Dim myFile As StreamWriter = IO.File.CreateText("Your path here") myFile.WriteLine(NumberOfClicks) myFile.Close() End Sub Sub Readnumber() 'to read it back in Dim myFile As StreamReader = IO.File.OpenText("Your path here") NumberOfClicks = Integer.Parse(myFile.ReadLine.Trim) myFile.Close() End Sub
Note there is no error trapping for things like illegal files and so forth.