|
-
May 12th, 2004, 04:20 PM
#1
Thread Starter
Frenzied Member
Writing to file?
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?
-
May 12th, 2004, 08:56 PM
#2
Sleep mode
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 .
-
May 13th, 2004, 06:06 AM
#3
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.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|