1

I saw a similar question on How can I read multiple text files and store them in a TextBox? , but it didn't really help with what I'm trying to do. I'm trying to load multiple Rich Text Files into 1 Rich Text Box, is that possible? My current code is this:

Private Sub LoadButton_Click(sender As Object, e As EventArgs) Handles LoadButton.Click

    Dim openFile1 As New OpenFileDialog()
    openFile1.DefaultExt = "*.rtf"
    openFile1.Filter = "RTF Files|*.rtf"


    Dim openFile2 As New OpenFileDialog()
    openFile2.DefaultExt = "*.rtf"
    openFile2.Filter = "RTF Files|*.rtf"

If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) And 
   (openFile2.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then

RichTextBox1.LoadFile(openFile1.FileName, openFile2.FileName)

End If

End Sub

It has no problem loading one file to the text box, but if I try to add the second file with the first, it crashes.

The current error that I get is "Conversion from string "C:\Software Development\Test\ann" to type 'Integer' is not valid."

C:\Software Development\Test\ann is the openFile2.FileName

Community
  • 1
  • 1
jdwee
  • 573
  • 1
  • 5
  • 15
  • If you read the [documentation](https://msdn.microsoft.com/en-us/library/ms160332(v=vs.110).aspx), you'll see that the only two-parameter call to LoadFile is looking for a filename (string) and a `RichTextBoxStreamType`, which is an enumeration. You can't just make up things to throw into method calls and expect them to work. – Ken White Jan 12 '17 at 18:42
  • Clearly that won't work because `.LoadFile()` doesn't have an overload which matches that or expects multiple file names. However, if you don't use `.LoadFile()` and instead there's some way to *manually* read from a file and append it to a RichTextBox, then you can do that as many times as you like. – David Jan 12 '17 at 18:43
  • I think you can't do that. Apart from the error in using LoadFile the main problem is your use of RTF files. You cannot simply merge them together using a RichTextBox. It has no functionality to do that. Instead with text files you simply load the first one with LoadFile and then call AppendText to append the second one. – Steve Jan 12 '17 at 18:51
  • Thanks guys, I'm kind of new to this, but I appreciate the feedback and thanks for the advice! – jdwee Jan 12 '17 at 18:53
  • To get some insight of the problem you can look at this question http://stackoverflow.com/questions/628553/merge-rtf-files – Steve Jan 12 '17 at 18:55

0 Answers0