Coyote Level: Guest

|
Re: Help Me :) Archived to Disk
Well here is a little example.
To run this Open a new project. Just to keep it working and loggin when you open and close the application. Set the ControlBox property to False. Not real necessary, but it keeps it so they use the Exit button and write to the file.
Next add a TextBox and set the Multiline Property to "True" and set the ScrollBars Property to "Both"
Next Add 3 command buttons...
Command1 change the Caption Property to "Write",
Command2 change the Caption property to "Read" and
Command3 change the Caption to "Exit"
Now Copy and paste the following code to Form1. Then Save the Project to some place and Run it
' **** Code Begins *****
Option Explicit
Private Sub Command1_Click()
Open App.Path & "history.txt" For Append As #1
Print #1, Text1.Text
Close #1
End Sub
Private Sub Command2_Click()
Dim strTextLine As String
Dim StrText As String
Open App.Path & "history.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strTextLine
If StrText = "" Then
' This keeps the first line from being blank due to the vbcrlf (carriage return)
StrText = strTextLine
Else
StrText = StrText + vbCrLf + strTextLine
End If
Loop
Text1.Text = StrText
Close #1
End Sub
Private Sub Command3_Click()
Dim ff As Integer
ff = FreeFile
' Edit the next line to the path and file name you want to use
Open App.Path & "history.txt" For Append As ff
Print #ff, "Application Closed " + Date$ + " " + Time$
Close ff
End
End Sub
Private Sub Form_Load()
' You could use this
'Dim ff As Integer
'ff = FreeFile
' and change all the following code where
' it has # 2 to ff and VB will take care of assigning the number
' and handle this for you. However - make sure you close ff
' Just for fun - I used #2 here. This could also be #1 as in
' all the above code - as long as you Close the file Example Close #2
' Edit the next line to the path and file name you want to use
' Example: Open "C:mytexthistory.txt For Append as # 2
' App.Path below uses the same folder you have you application
' saved at.
Open App.Path & "history.txt" For Append As #2
Print #2, "Application Opened " + Date$ + " " + Time$
Close #2
End Sub
' ***** CODE ENDS ********
When you run this code, it will write to the file the application name, date and time everytime you open and everytime you close the program. Also if you clear the text box and type something in it and click the "Write" button it will write that to the file. To see everything in the file.. click the "Read" button.
Best of luck... hope this answers you question
Take Care...
>>>Coyote<<
|