How to Create a Notepad Program


1. Create a new Visual Basic 6.0 (VB6) project using the “Standard EXE” template. Click on “File” in the top VB6 menu and select “Save Project As.” The first prompt asks for a form name. Name the form “MyNotePad” and click “OK.” The next prompt asks for the project name. Name it “My Notepad” and click “OK.”
2. Click on “Project” in the top VB6 menu and select “Components.” Scroll down the list of components until you see “Microsoft Common Dialog Control 6.0.” Click on the checkbox next to this to add this control, and then click “OK.” Double-click on this control, which should be the last item in the toolbox on the left, to add it to the form.
3. Locate the Properties box on the right of the screen and double-click on the first item, “(Name).” Change the default name to “MyNotePad.\" Double-click on the “Caption” property and change this name to “My Note Pad.\"
4. Double-click on the TextBox icon in the toolbox panel on the left of the screen to add this to the form. Click on the new control and use the drag handles to enlarge the TextBox to nearly the size of the form itself. Locate the TextBox control in the Properties panel on the right of the screen and make these changes:<br /><br />(Name) = MyNote<br />Multiline = True<br />ScrollBars = 3-Both
5. Click “Tools” in the top VB6 menu and select “Menu Editor.” Make these changes in the Menu Editor box that opens, clicking “Next” after each of the first two menus and “Exit” after the last one as shown below:<br /><br />Caption = Print<br />Name = mnuPrint<br />Click “Next”<br />Caption = Save<br />Name = mnuSave<br />Click “Next”<br />Caption = Exit<br />Name = mnuExit<br />Click “OK”
6. Open the Code window by clicking on “View” and then “Code” in the top level VB6 menu. Type the following lines of code exactly as they appear below:<br /><br />Sub form_load()<br />End Sub<br />Function SaveMyNote(MyNote As Control, CommonDialog1 As CommonDialog, Filename As String) As Boolean<br />Dim fNum As Integer<br />On Error GoTo ExitNow<br />CommonDialog1.Filter = \"Text Files | *.txt\"<br />CommonDialog1.Filename = Filename<br />CommonDialog1.CancelError = True<br />CommonDialog1.ShowSave<br />Filename = CommonDialog1.Filename<br />fNum = FreeFile()<br />Open Filename For Output As #fNum<br />Print #fNum, MyNote.Text<br />GO<br />Close #fNum<br />SaveMyNote = True<br />ExitNow:<br />End Function<br />Private Sub mnuPrint_Click()<br />With CommonDialog1<br />.PrinterDefault = True<br />.ShowPrinter<br />Printer.Print MyNote.Text<br />Printer.EndDoc<br />End With<br />End Sub<br />Private Sub mnuSave_click()<br />Dim Filename As String<br />If SaveMyNote(MyNote, CommonDialog1, Filename) Then<br />MsgBox \"Your note has been saved to \" & Filename<br />End If<br />End Sub<br />Private Sub mnuExit_Click()<br />End<br />End Sub
7. Press “F5” to run the program. Type whatever you like in the box and print or save it using the menu items.

0 comments:

Post a Comment