Results 1 to 4 of 4

Thread: opening doc into a richtext box , with commondialog

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    5

    Question

    im using commondialog, i want to open a .doc, or .txt, whatever.. and load it into a richtext box. but i always get errors.. anyone know how.. thanks
    later
    Vb6 EE

  2. #2
    Guest
    Try this:

    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        On Error GoTo User_Cancelled
        With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select a Text File.."
        .Filter = "Txt Files (*.txt)|*.txt|Doc Files (*.doc)|*.doc"
        .ShowOpen
        iFile = FreeFile
        Open .filename For Input As iFile
        RichTextBox1.text = Input(LOF(iFile), iFile)
        Close iFile
        End With
    User_Cancelled:
    End Sub

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    That will only work with TXT files.
    For opening TXT and RTF, you can use the LoadFile method.
    I think it's:
    Code:
    ' Text files:
    RichTextBox1.LoadFile("C:\MyFile.txt", vbCFText)
    ' RichText files:
    RichTextBox1.LoadFile("C:\MyFile.rtf", vbCFRTF)
    If it's not LoadFile then it's FileLoad or OpenFile or FileOpen or maybe I'm just tired...

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    5

    Lightbulb

    yea.. i finally seen that loadfile. im a retard..
    thanks

    later
    Vb6 EE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width