feedburner
Enter your email address:

Delivered by FeedBurner

feedburner count

Making Notepad in Visual Basic 6.0 (Not so simple!)

This tutorial is not simple . Open Vb6.0 and select Standard .EXE . Add TextBox (On all form), Microsoft Common Dialog 6.0 (Project ~> Components ...)  and use menu editor to create the menus : File (New , Open , save , Exit ) , Edit (undo , cut ,copy,paste) , Format (fonT) and Help(About , if u like it).Set  Text1 Multiline = true text1 ScroolBars - Both
.Add 1 Module with this codE:

Private Const EM_CANUNDO = &HC6
Private Const EM_UNDO = &HC7


Private Declare Function SendMessage Lib "user32" _
        Alias "SendMessageA" _
        (ByVal hwnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        lParam As Any) As Long


Public Function CanUndo(ByVal hwnd As Long) As Boolean
    CanUndo = SendMessage(hwnd, EM_CANUNDO, 0&, 0&)
End Function
Public Sub ControlUndo(ByVal hwnd As Long)
    SendMessage hwnd, EM_UNDO, 0&, 0&
End Sub


The form code now : (My menu names are : new,open,save,exit,paste,cut,copy,font => like the caption )
Private Sub copy_Click(Index As Integer)
Clipboard.SetText Text1.SelText
End Sub

Private Sub cut_Click(Index As Integer)
Clipboard.SetText Text1.SelText
Text1.Text = ""

End Sub

Private Sub font_Click(Index As Integer)
With dlg  'open the with dialog
     .DialogTitle = "Font"   'set the dialog title
     .Flags = cdlCFBoth Or cdlCFEffects   'set the flags so you can
     'access the fonts* and the strikethru, underline, color

     .ShowFont  'show the dialog
End With

Text1.FontName = dlg.FontName  'set the selected font’s name
Text1.FontSize = dlg.FontSize  'set the selected font’s size
Text1.FontBold = dlg.FontBold  'set the selected font’s bold property
Text1.FontItalic = dlg.FontItalic  'set the selected font’s italic property
Text1.FontStrikethru = dlg.FontStrikethru  'set the selected font’s strikethrough property
Text1.FontUnderline = dlg.FontUnderline  'set the selected font’s underline property
End Sub

Private Sub exit_Click(Index As Integer)
If Text1.Text = "" Then
End
Else
Dim yesnocancel As Integer
yesnocancel = MsgBox("You close the notepad with written text.Do you want to save it?", vbExclamation + vbYesNoCancel, "DBZ-Notepad")
If yesnocancel = vbYes Then
    
With dlg
.Filter = "Txt Files (*.txt) |  *.txt"
    .DialogTitle = "Save"
    .ShowSave
    .CancelError = True
End With
Open dlg.FileName For Append As #1
Print #1, Text1.Text
Close #1
End If
End If
If yesnocancel = vbNo Then
End
End If
If yesnocancel = vbCancel Then

End If
End Sub



Private Sub Form_Unload(Cancel As Integer)
If Text1.Text = "" Or Text1.Text = " " Then
End
Else
Dim yesnocancel As Integer
yesnocancel = MsgBox("You close the notepad with written text.Do you want to save it?", vbExclamation + vbYesNoCancel, "DBZ-Notepad")
If yesnocancel = vbYes Then
With dlg
.Filter = "Txt Files (*.txt) |  *.txt"
    .DialogTitle = "Save"
    .ShowSave
    .CancelError = True
End With
Open dlg.FileName For Append As #1
Print #1, Text1.Text
Close #1
End If
End If
If yesnocancel = vbNo Then
End
End If
If yesnocancel = vbCancel Then
End If
End Sub

Private Sub new_Click(Index As Integer)
Text1.Text = ""
End Sub

Private Sub open_Click(Index As Integer)
On Error GoTo a:
Dim filelocation As String

With dlg
    .ShowOpen
    .Filter = "Text Files (*.txt) |  *.txt"
    .DialogTitle = "Open"
    End With

    filelocation = dlg.FileName
Text1.Text = ""
    Open filelocation For Input As #1
Do Until EOF(1)
        Input #1, Data
        Text1.Text = Text1.Text + Data + vbNewLine
    EOF (1)
    Loop
    Close #1
    
a:
End Sub


Private Sub paste_Click(Index As Integer)
Text1.Text = Text1.Text + Clipboard.GetText
End Sub

Private Sub save_Click(Index As Integer)
Dim fnx As String
On Error GoTo a
With dlg
.Filter = "Txt Files (*.txt) |  *.txt"
    .DialogTitle = "Save"
    .ShowSave
    
End With
Open dlg.FileName For Append As #1
fnx = dlg.FileName
MsgBox "You saved text in : " & fnx, vbInformation, "DBZ-Notepad"
Print #1, Text1.Text
Close #1
a:
End Sub

Private Sub undo_Click(Index As Integer)
If CanUndo(Screen.ActiveControl.hwnd) = True Then
        ControlUndo Screen.ActiveControl.hwnd
    End If
End Sub

You done. It works.
If u have any questions or suggestions just comment!
Note: The version is bugged because its new ( Like in Open command , Exit (Unload ) and so on. ) So dont tell me about my bugs i kn0w it :P 




1 comments:
gravatar
Anindya Tirta said...
December 1, 2014 at 5:40 AM  

Nice job.But why you not add "Print" features?

Post a Comment