Wednesday, May 27, 2009

Sample Program : Creating a text file

Creating files To create a file , we use the following command
Open "fileName" For Output As #fileNumber
Each file created must have a file name and a file number for identification. As for the file name, you must also specify the path where the file will reside.
Examples:

Open "c:\My Documents\sample.txt" For Output As #1

will create a text file by the name of sample.txt in My Document folder. The accompany file number is 1. If you wish to create and save the file in A drive, simply change the path, as follows"
Open "A:\sample.txt" For Output As #1
If you wish to create a HTML file , simply change the extension to .html

Open "c:\My Documents\sample.html" For Output As # 2



Sample Program : Creating a text file

Private Sub create_Click()

Dim intMsg As String
Dim StudentName As String

Open "c:\My Documents\sample.txt" For Output As #1
intMsg = MsgBox("File sample.txt opened")
StudentName = InputBox("Enter the student Name")
Print #1, StudentName
intMsg = MsgBox("Writing a" & StudentName & " to sample.txt ")

Close #1

intMsg = MsgBox("File sample.txt closed")

End Sub

* The above program will create a file sample.txt in the My Documents' folder and ready to receive input from users. Any data input by users will be saved in this text file.

No comments:

Post a Comment