Visual Basic: RichTextBox Control

LoadFile Method

See Also    Example    Applies To

Loads an .rtf file or text file into a RichTextBox control.

Syntax

object.LoadFilepathname, filetype

The LoadFile method syntax has these parts:

Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
pathname Required. A string expression defining the path and filename of the file to load into the control.
filetype Optional. An integer or constant that specifies the type of file loaded, as described in Settings.

Settings

The settings for filetype are:

Constant Value Description
rtfRTF 0 (Default) RTF. The file loaded must be a valid .rtf file.
rtfText 1 Text. The RichTextBox control loads any text file.

Remarks

When loading a file with the LoadFile method, the contents of the loaded file replaces the entire contents of the RichTextBox control. This will cause the values of the Text and RTFText properties to change.

You can also use the Input function in Visual Basic and the TextRTF and SelRTF properties of the RichTextBox control to read .rtf files. For example, you can load the contents of an .rtf file to the RichTextBox control as follows:

Open "mytext.rtf" For Input As 1

RichTextBox1.TextRTF = Strconv(InputB$(LOF(1), 1), vbUnicode)