VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to make a simple notepad in visual basic

by king (24 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 26th January 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

How to make a simple notepad in visual basic

API Declarations


you will need a richtextbox and commondialogbox control
please make sure to name the common dialog box control (cd)
make menus such as new open , save ,saveas lets start...

Rate How to make a simple notepad in visual basic



Private Sub menuopen_Click()
' will call the procedure optionopen here'
On Error Resume Next
Call optionopen
End Sub
optionopen is a procedure to open files
Private Sub optionopen()
Dim whatfile As String
Dim file1 As FileAttribute
Dim ask As String
  If rtbox.Text = "" Then
  cd.CancelError = False
  cd.Filter = " txtfiles (*.txt)|*.txt| All files (*.*)|*.*|"
  cd.Action = 1
  rtbox.FileName = cd.FileName
  frmmain.Caption = cd.FileName & " - " & " NotePad "
  menusave.Enabled = True
  ' here we taken a commondialogcontrol which we have name as cd'
  'the first line says that if the cancel button is pressed nothing will happen'
  'the second line tells is the extension of the file such as *.txt ,*.rtf ect...'
  'the third line tells is the open dialogbox'
  ' the fourth line explains the loadfile method'
  Else
  ' the condition states that if the file is already open and you want to open an another file it prompts a message box'
  ' if the user presses the yes button then it saves the file otherwise if the user presses no then it prompts an open dialogbox to open a file'
  ' we call the open method again'
   ask = MsgBox(" The file in the note has been changed! " & vbCr & " do you want to save changes you made to the file? ", vbYesNo + vbExclamation)
     If ask = (vbYes) Then
  cd.ShowOpen
  ElseIf ask = (vbNo) Then
   cd.CancelError = False
  cd.Filter = " txtfiles (*.txt)|*.txt|"
  cd.Action = 1
  rtbox.FileName = cd.FileName
    frmmain.Caption = cd.FileName & " - " & " NotePad "

  End If
   End If
End Sub
**************************************************************************
on the save event write this code
Private Sub menusaveas_Click()
' we call this procedure saveall'
saveall
menusave.Enabled = True
  frmmain.Caption = cd.FileName & " - " & " NotePad "
End Sub
saveall is a procedure to save files to your harddrive
Private Sub saveall()
On Error Resume Next
cd.Filter = " txtfiles (*.txt)|*.txt| All files (*.*)|*.*|"
cd.Flags = cd10FNOverWritePropmt
cd.InitDir = Directory
cd.ShowSave
rtbox.SaveFile cd.FileName
SavePicture picturename, cd.FileName

 ' if the file already exsist a message box will appear in front of the screen that file already exsist replace the data in the file'
End Sub
on the save event write this code
**************************************************************************
Private Sub menusave_Click()
On Error Resume Next
Dim picturename As String
rtbox.SaveFile cd.FileName
SavePicture Picture, rtbox.Text
cd.InitDir = Directory
cd.DefaultExt = ".txt"
cd.Copies = 1
frmmain.Caption = cd.FileName & " - " & " NotePad "
End Sub
on the new page event write this code
Private Sub menunew_Click()
On Error Resume Next
'we will call the procedure optionnew'
Call optionnew
End Sub
option all is a procedure for a new page event
Private Sub optionopen()
Dim whatfile As String
Dim file1 As FileAttribute
Dim ask As String
  If rtbox.Text = "" Then
  cd.CancelError = False
  cd.Filter = " txtfiles (*.txt)|*.txt| All files (*.*)|*.*|"
  cd.Action = 1
  rtbox.FileName = cd.FileName
  frmmain.Caption = cd.FileName & " - " & " NotePad "
  menusave.Enabled = True
  ' here we taken a commondialogcontrol which we have name as cd'
  'the first line says that if the cancel button is pressed nothing will happen'
  'the second line tells is the extension of the file such as *.txt ,*.rtf ect...'
  'the third line tells is the open dialogbox'
  ' the fourth line explains the loadfile method'
  Else
  ' the condition states that if the file is already open and you want to open an another file it prompts a message box'
  ' if the user presses the yes button then it saves the file otherwise if the user presses no then it prompts an open dialogbox to open a file'
  ' we call the open method again'
   ask = MsgBox(" The file in the note has been changed! " & vbCr & " do you want to save changes you made to the file? ", vbYesNo + vbExclamation)
     If ask = (vbYes) Then
  cd.ShowOpen
  ElseIf ask = (vbNo) Then
   cd.CancelError = False
  cd.Filter = " txtfiles (*.txt)|*.txt|"
  cd.Action = 1
  rtbox.FileName = cd.FileName
    frmmain.Caption = cd.FileName & " - " & " NotePad "

  End If
   End If
End Sub
*******************************************************************



Download this snippet    Add to My Saved Code

How to make a simple notepad in visual basic Comments

No comments have been posted about How to make a simple notepad in visual basic. Why not be the first to post a comment about How to make a simple notepad in visual basic.

Post your comment

Subject:
Message:
0/1000 characters