Dim bestandsnaam As String
Dim IsOpgeslagen As Boolean
Private Sub Form_Load()
mnuFileClose.Caption = mnuFileClose.Caption & Chr(9) & "Alt+F4"
mnuEditCopy.Caption = mnuEditCopy.Caption & Chr(9) & "Ctrl+C"
mnuEditPaste.Caption = mnuEditPaste.Caption & Chr(9) & "Ctrl+V"
mnuEditCut.Caption = mnuEditCut.Caption & Chr(9) & "Ctrl+X"
mnuEditDelete.Caption = mnuEditDelete.Caption & Chr(9) & "Del"
IsOpgeslagen = True
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If IsOpgeslagen = False Then
Select Case MsgBox("Je bestand is niet opgeslagen. Wil je nu opslaan?",
vbYesNoCancel + vbExclamation)
Case vbYes
mnuFileSaveas_Click
Case vbNo
'niets doen
Case vbCancel
Cancel = 1
End Select
End If
End Sub
Private Sub Form_Resize()
txtText.Top = 0
txtText.Left = 0
txtText.Width = Me.Width - 100
txtText.Height = Me.Height - 700
End Sub
Private Sub mnuEditCopy_Click()
Clipboard.SetText txtText.SelText
End Sub
Private Sub mnuEditCut_Click()
Clipboard.SetText txtText.SelText
txtText.SelText = ""
End Sub
Private Sub mnuEditDelete_Click()
txtText.SelText = ""
End Sub
Private Sub mnuEditPaste_Click()
txtText.SelText = Clipboard.GetText
End Sub
Private Sub mnuFileClose_Click()
Unload Form1
End Sub
Private Sub mnuFileNew_Click()
Dim f As New Form1
f.Show
End Sub
Private Sub mnuFileOpen_Click()
On Error GoTo OpenError
CommonDialog1.Filter = "Tekstbestanden|*.txt|Alle bestanden|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
txtText.Text = ""
Open CommonDialog1.FileName For Input As #1
Dim lijn As String
Do While Not EOF(1) 'eof = end of file / einde bestand bereikt
Input #1, lijn
txtText.Text = txtText.Text & vbCrLf & lijn 'vbCrLf: regeleinde
Loop
Close #1
bestandsnaam = CommonDialog1.FileName
Exit Sub
OpenError:
Select Case MsgBox(Err.Description, vbAbortRetryIgnore + vbCritical)
Case vbAbort
Resume 0
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
End Sub
Private Sub mnuFileSave_Click()
If bestandsnaam = "" Then
mnuFileSaveas_Click
Exit Sub
End If
Open bestandsnaam For Output As #1
Print #1, txtText.Text
Close #1
IsOpgeslagen = True
End Sub
Private Sub mnuFileSaveas_Click()
On Error GoTo SaveError
CommonDialog1.DefaultExt = "txt"
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Output As #1
Print #1, txtText.Text
Close #1
IsOpgeslagen = True
bestandsnaam = CommonDialog1.FileName
Exit Sub
SaveError:
Select Case MsgBox(Err.Description, vbAbortRetryIgnore + vbCritical)
Case vbAbort
Resume 0
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
End Sub
Private Sub mnuFormat_Click()
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
CommonDialog1.ShowFont
txtText.FontName = CommonDialog1.FontName
txtText.FontSize = CommonDialog1.FontSize
txtText.FontBold = CommonDialog1.FontBold
End Sub
Private Sub txtText_Change()
IsOpgeslagen = False
End Sub