Solved

Form not unloading after assigning a picture to an Image control

Posted on 2000-04-19
9
146 Views
Last Modified: 2010-05-02
My About box's Form_Load contains the following line of code:

imgIcon.Picture = frmMain.Icon

to display main form's icon in an Image control. When I close the dialog and then close my program, the About box is not unloaded, so the program does not really end. I've commented out that line and then the program ends correctly. The same happens with PictureBox controls. Any hints?
0
Comment
Question by:luisr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731537
to ensure you are closing all forms do this:

Private Sub Form_Unload(Cancel As Integer)
    Dim frm As Form
    For Each frm In Forms
        If frm.hWnd <> Me.hWnd Then _
            Unload frm
    Next
    Unload Me
End Sub

0
 
LVL 3

Author Comment

by:luisr
ID: 2731846
That would do it, but I still want to know why the form is still loaded after a call to Unload Me.

BTW, I'm using VB 5.0.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731874
I would imagine because he is referencing the icon from your main form which is not unloaded yet.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:luisr
ID: 2731888
I tried imgIcon.Picture = LoadPicture() before unloading the form and it did not work.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731906
try this:

Set imgIcon.Picture = Nothing
0
 
LVL 3

Author Comment

by:luisr
ID: 2731937
It does not work.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2732013
why dont you just do as i stated earlier and close all the forms?  are you saying that you close the about box and then close the main form and then the about box form suddenly reappears?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 2732072
You line
imgIcon.Picture = frmMain.Icon
will load the form "frmMain" (into memory), in order to be able to access the icon data.
So it is the frmMain that remains loaded, not the About form!
If you want to unload that form, you need to add a line like
Unload frmMain
immediately after your first line.

Hope this illuminates you
0
 
LVL 3

Author Comment

by:luisr
ID: 2732202
You're right angelIII, it's frmMain that remains in memory. Although your solution works (unloading frmMain), I did something else. I changed my code to copy the icon from the global variable fMainForm, which is an instance of frmMain.

Thanks for the tip!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question