Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '***********************************************************************
- 'Agregar el código fuente a los formularios y al módulo bas
- '************************************************************************
- 'Código fuente a colocar en el Formulario Mdi
- '************************************************************************
- Option Explicit
- Private Sub MDIForm_Initialize()
- CommonDialog1.Filter = "Documento de texto|*.txt|Todos los Archivos|*.*"
- End Sub
- 'Menú abrir
- Private Sub mnuAbrir_Click()
- On Error GoTo errSub
- CommonDialog1.ShowOpen
- If CommonDialog1.FileName <> "" Then
- Set FrmDoc = New frmDocumento
- FrmDoc.Show
- ActiveForm.Caption = CommonDialog1.FileName
- ActiveForm.RichTextBox1.LoadFile CommonDialog1.FileName
- End If
- Exit Sub
- errSub:
- Select Case Err.Number
- Case 70
- ActiveForm.RichTextBox1.LoadFile CommonDialog1.FileName
- Resume Next
- End Select
- End Sub
- 'Menu Guardar Como
- Private Sub mnuGuarcomo_Click()
- On Error GoTo errSub
- If Forms.Count = 1 Then
- MsgBox "No hay documentos para guardar", vbInformation
- Exit Sub
- End If
- CommonDialog1.ShowSave
- If CommonDialog1.FileName = "" Then Exit Sub
- ActiveForm.RichTextBox1.SaveFile CommonDialog1.FileName
- Exit Sub
- errSub:
- Select Case Err.Number
- Case 91
- Resume Next
- End Select
- End Sub
- 'Menú para guardar el archivo
- Private Sub mnuGuardar_Click()
- On Error GoTo errSub
- If Forms.Count = 1 Then
- MsgBox "No hay documentos para guardar", vbInformation
- Exit Sub
- End If
- If InStr(1, ActiveForm.Caption, sCaption) Then
- CommonDialog1.ShowSave
- If CommonDialog1.FileName = "" Then Exit Sub
- ActiveForm.RichTextBox1.SaveFile CommonDialog1.FileName
- Else
- ActiveForm.RichTextBox1.SaveFile ActiveForm.Caption
- End If
- Exit Sub
- errSub:
- Select Case Err.Number
- Case 91
- Resume Next
- End Select
- End Sub
- 'Menú nuevo archivo
- Private Sub mnuNuevo_Click()
- Set FrmDoc = New frmDocumento
- nForms = nForms + 1
- FrmDoc.Caption = sCaption & nForms
- FrmDoc.Show
- End Sub
- 'Menú pegar
- Private Sub mnuPegar_Click()
- On Local Error Resume Next
- ActiveForm.RichTextBox1.SelText = Clipboard.GetText
- End Sub
- 'Menú salir
- Private Sub mnuSalir_Click()
- Set FrmDoc = Nothing
- End
- End Sub
- 'Menu para seleccionar todo el texto
- Private Sub mnuSeleccionar_Click()
- On Local Error Resume Next
- ActiveForm.RichTextBox1.SelStart = 0
- ActiveForm.RichTextBox1.SelLength = Len(ActiveForm.RichTextBox1.Text)
- End Sub
- 'Menú Copiar texto
- Private Sub mnuCopiar_Click()
- On Local Error Resume Next
- Clipboard.SetText ActiveForm.RichTextBox1.SelText
- End Sub
- 'Menú cortar texto
- Private Sub mnuCortar_Click()
- On Local Error Resume Next
- Clipboard.SetText ActiveForm.RichTextBox1.SelText
- ActiveForm.RichTextBox1.SelText = ""
- End Sub
- '***********************************************************************
- 'Código fuente a colocar en el formulario frmDocumento
- '***********************************************************************
- Option Explicit
- Public flagGuardar As Boolean
- Private Sub Form_Resize()
- 'Redimensionamos el control RichtextBox al ancho y alto del formulario
- RichTextBox1.Move ScaleLeft, ScaleTop, ScaleWidth, ScaleHeight
- If WindowState = vbMaximized Then
- 'mdiform1.Caption = Me.Caption
- Else
- mdiform1.Caption = ""
- End If
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- On Error GoTo errSub
- Dim ret As Integer
- If flagGuardar Then
- ret = MsgBox(" Guardar cambios", vbYesNoCancel)
- End If
- Select Case ret
- Case vbYes:
- If InStr(1, Me.Caption, sCaption) Then
- CommonDialog1.ShowSave
- RichTextBox1.SaveFile CommonDialog1.FileName
- Else
- RichTextBox1.SaveFile Me.Caption
- End If
- Case vbCancel:
- Exit Sub
- End Select
- Set FrmDoc = Nothing
- Exit sub
- errSub:
- Select Case Err.Number
- Case 75
- Resume Next
- End Select
- End Sub
- Private Sub RichTextBox1_Change()
- flagGuardar = True
- End Sub
- '***********************************************************
- 'Código fuente a colocar en el Módulo bas
- '***********************************************************
- Public FrmDoc As frmDocumento
- Public nForms As Integer
- Public Const sCaption = "Nuevo documento sin título "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement