Solved

Form not unloading after assigning a picture to an Image control

Posted on 2000-04-19
9
144 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Computer crashes, following error message in event manager 5 240
How to incorporate an error traping routing to existing code in VB6 11 45
MsgBox 4 68
RUNRMTCMD from AS/400 12 69
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

829 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