Hi *
Open .txt files and print without fuss.
You need a form, three buttons, a common dialog control, and a rich text box.
Private Sub Command1_Click()
' The RichTextBox control is named "rtfData."
' The CommonDialog is named "dlgOpenFile."
' Declare a String variable for file name.
' Show the Open File dialog box, and set the
' variable to the filename.
Dim strOpen As String
CommonDialog1.ShowOpen
strOpen = CommonDialog1.filename
' Use LoadFile method to open the file.
RichTextBox1.LoadFile strOpen
End Sub
'To save a file is just as easy, using the SaveFile method:
Private Sub SaveFile()
Dim strNewFile As String
dlgOpenFile.ShowSave
strNewFile = dlgOpenFile.filename
rtfData.SaveFile strNewFile
End Sub
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
If RichTextBox1.SelLength = 0 Then
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPages
Else
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelection
End If
CommonDialog1.ShowPrinter
Printer.Print ""
RichTextBox1.SelPrint CommonDialog1.hDC
End Sub