PRB: Out of Memory Error Adding GIF Files to RichTextBox Control (264405)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q264405 SYMPTOMS
On Microsoft Windows 2000, when you add a Graphics Interchange Format (GIF) file to a RichTextBox control followed by the addition of another GIF, you get the following error message:
Runtime Error 7: Out of Memory
Under Microsoft Windows 9x or Microsoft NT 4.0, the error message appears when you add the first GIF to the RichTextBox.
CAUSE
The addition of the first GIF file spawns the Photo Editor, which causes an error message under Windows 9x or NT 4.0. Under Windows 2000, when the second GIF file is added, the error occurs because Photo Editor is already open. So under Windows 2000, if you close the Photo Editor manually before executing the line of code that adds the second GIF, the error does not occur.
RESOLUTION
The workaround is to convert the GIF files into bitmaps (BMP) by saving them from a PictureBox control. Adding a BMP to a RichTextBox invokes the in-place activated Paint Editor instead of the Photo Editor.
In the following sample, you need to change the GIF file names to match the files that you are using on your system.
Step-by-Step Example- Create a new Standard EXE project in Visual Basic. Form1 is created by default.
- Add a PictureBox control to Form1 and set its Visible property to False.
- Add the RichTextBox control to the Toolbox.
- On the Project menu, click to select Components, select the Microsoft Rich Textbox Control , and then click OK.
- Add a RichTextBox control to Form1.
- Place two GIF files in the application folder. This is the folder that contains the project file (.vbp) or executable file (.exe). For new (unsaved) projects, this is the ...\vb98 folder by default. Make sure that the actual file names are used in the following code or an else an error occurs.
- Add the following code to Form1:
Private Sub Form_Click()
RichTextBox1.Text = ""
Picture1.Picture = LoadPicture(App.Path & "\c663dn5a.gif")
DoEvents
SavePicture Picture1.Picture, App.Path & "\c663dn5a.bmp"
DoEvents
RichTextBox1.OLEObjects.Add , , App.Path & "\c663dn5a.bmp"
DoEvents
RichTextBox1.SelStart = 1
Picture1.Picture = LoadPicture(App.Path & "\c663dn5b.gif")
DoEvents
SavePicture Picture1.Picture, App.Path & "\c663dn5b.bmp"
DoEvents
RichTextBox1.OLEObjects.Add , , App.Path & "\c663dn5b.bmp"
RichTextBox1.SelStart = Len(RichTextBox1.Text)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
RichTextBox1.OLEObjects.Clear
End Sub
- Run the project, and note that both images are loaded into the RichTextBox.
Modification Type: | Major | Last Reviewed: | 10/15/2002 |
---|
Keywords: | kbBug kbCodeSnippet kbCtrl kbDSupport kbprb KB264405 |
---|
|