1. Option Explicit
2. 'Set a reference to "Microsoft Scripting Runtime"
3. Private Sub Command1_Click()
4. 'declare and initiate required objects
5. Dim fs As FileSystemObject
6. Dim ts As TextStream
7.
8. Set fs = New FileSystemObject
9.
10. 'To write
11. Set ts = fs.OpenTextFile("C:\mytestfile.txt", ForWriting, True)
12. ts.WriteLine "I Love"
13. ts.WriteLine "VB Forums"
14. ts.Close
15.
16. 'To Read
17. If fs.FileExists("C:\mytestfile.txt") Then
18. Set ts = fs.OpenTextFile("C:\mytestfile.txt")
19.
20. Do While Not ts.AtEndOfStream
21. MsgBox ts.ReadLine
22. Loop
23. ts.Close
24. End If
25.
26. 'clear memory used by FSO objects
27. Set ts = Nothing
28. Set fs = Nothing
29. End Sub