Results 1 to 3 of 3

Thread: Writing to file?

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    This should start you off, I haven't tested it so it might be wrong...


    VB Code:
    1. Dim NumberOfClicks As Integer = 31 'the variable youwant to write
    2.  
    3.     Sub WriteNumber()
    4.  
    5.         'to write text file
    6.         Dim myFile As StreamWriter = IO.File.CreateText("Your path here")
    7.         myFile.WriteLine(NumberOfClicks)
    8.         myFile.Close()
    9.  
    10.     End Sub
    11.  
    12.     Sub Readnumber()
    13.  
    14.         'to read it back in
    15.         Dim myFile As StreamReader = IO.File.OpenText("Your path here")
    16.         NumberOfClicks = Integer.Parse(myFile.ReadLine.Trim)
    17.         myFile.Close()
    18.  
    19.     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
  •  



Click Here to Expand Forum to Full Width