Simple Text Editor
Learn to make a Simple Text Editor using Visual Basic 6 with this Tutorial that Celebrates the CESPage 25th Anniversary
Text Editing is one of the most common tasks performed on a computer, so here is a simple one which will introduce you to the Text Box Control plus a little about Input Boxes and using Files.
Step 1
Step 2
Step 3
Step 4
Step 5
MultiLine
to True
and ScrollBar
to 2 - Vertical
Step 6
Step 7
Step 8
Caption
of Command3
to Quit
using the Properties Box
Step 9
Caption
of Command2
to Save
and the Caption
of
Command1
to Load
, using the Properties Box for each Command Button
Step 10
Double Click on the Command Button labelled Load or Command1
and type in the Command1_Click()
Sub
Dim strName As String, strFile As String, strTemp As String
On Error GoTo ErrHandler
strName = InputBox("Filename:")
Open strName For Input As #1
strFile = ""
Do Until EOF(1)
Line Input #1, strTemp
strFile = strFile & strTemp & vbCrLf
Loop
Text1.Text = strFile
Close #1
ErrHandler:
Step 11
Double Click on the Command Button labelled Save or Command2
and type in the Command2_Click()
Sub
Dim strName As String
On Error GoTo ErrHandler
strName = InputBox("Filename:")
Open strName For Output As #1
Print #1, Text1.Text
Close #1
ErrHandler:
Step 12
Double Click on the Command Button labelled Quit or Command3
and type in the Command3_Click()
Sub
Unload Me
Step 13
Step 14
Step 15
Step 16
That was simple wasn't it? It can Load and Save Text Files! Try changing the program so that it checks whether a file exists for Load and Save. Try changing other parts of the code and extending it, you can learn a lot from this Simple Text Editor, try and see if you can modify this example to use the Common Dialog box!