Things You'll Need:
- Visual Basic 6.0
-
Step 1
Open Visual Basic 6.0, click File and choose New Project. Select Standard EXE from the list of templates. Double-click the TextBox control in the Toolbox on the left to add this to the form. Change the height of the Form in the Properties pane on the right to 5000.
-
Step 2
Make the following changes to the TextBox Properties:
Height = 3000
Multiline=True
Scrollbars=Both
Width=3000 -
Step 3
Double-click the Button control in the Toolbox. Change the Caption property to Read File. Repeat this operation to add a second Button control, changing the Caption property here to Write File.
-
Step 4
Double-click the Read File button to open the code window. Enter this code on the code view page:
Function ReadFile()
Dim ReadFileName As String
ReadFile = InputBox("Enter name of file to read:")
Open ReadFile For Input As #1
ReadFile = Input$(LOF(1), 1)
Text1.Text = ReadFile
Close #1
End Function
Private Sub Command1_Click()
ReadFile
End Sub -
Step 5
Double-click the Write File button to open the code window. Enter this code:
Function WriteFile()
Dim WriteFileName As String
WriteFileName = InputBox("Enter file name")
Open WriteFileName For Output As #2
Print #2, Text1.Text
Close #1
End Function
Private Sub Command2_Click()
WriteFile
End Sub -
Step 6
Run the program by pressing F5 and click on the Read File command first. Enter the name of a known text file, including the .txt suffix. The file should appear in the TextBox. If you now click on Write File and provide a different name, you will create a new but duplicate file. Alternatively, if you delete the text or just click on Read File before loading a file and then type something new, you can create a completely new file.













