Solved

another control array question - BergJC

Posted on 1998-10-23
6
137 Views
Last Modified: 2010-04-30
We have discovered that the reason the unload image does not work properly when we are choosing an item from a combo box click or change.

How do you trick it to make it think it's coming from a command button which works fine.
0
Comment
Question by:MaryD
  • 4
  • 2
6 Comments
 
LVL 7

Expert Comment

by:kamall
Comment Utility
Please be more clear on what you are trying to do exactly so we can help you. Probably you can post your code as well.
0
 

Author Comment

by:MaryD
Comment Utility
Create-load 5 control array elements  (command1)
       --always succesful
         if the array element contains 1 element imgTest(0)
Remove-unloads the 5 control array elements (command2)
       always successful
Combo-successful first time through in loading control array
     -subsequent passes
       -tries to unload(5 control array elements)
       -receives error
         "unlable to unload in this context"
       


Option Explicit
Public Intx As Integer
Public d, z As Integer
Public Frst As Integer

Private Sub cboTest_click()
If Frst = 0 Then
    unloadarray
End If
Frst = 0
For d = 1 To z
    Load imgTest(d)
    imgTest(d).Height = 615
    imgTest(d).Width = 615
    imgTest(d).Top = 615
    imgTest(d).Left = (615 * d)
    imgTest(d).Visible = True
Next
End Sub

Private Sub cmdStop_Click()
End
End Sub

Private Sub Command1_Click()

For d = 1 To z
    Load imgTest(d)
    imgTest(d).Height = 615
    imgTest(d).Width = 615
    imgTest(d).Top = 615
    imgTest(d).Left = (615 * d)
    imgTest(d).Visible = True
Next
End Sub

Private Sub Command2_Click()
For d = 1 To z
    Unload imgTest(d)
    Intx = Intx - 1
Next
Frst = 1
End Sub

Private Sub Form_Load()
z = 5
Frst = 1
End Sub
Private Sub unloadarray()
For d = 1 To z
    Unload imgTest(d)
    Intx = Intx - 1
Next
End Sub

0
 
LVL 7

Accepted Solution

by:
kamall earned 50 total points
Comment Utility
MaryD,
I tested your code and looked at the problem. Here is the cause:
(Form the VB help file)

Unable to unload within this context (Error 365):

In some situations you are not allowed to unload a form or a control on a form. This error has the following causes and solutions:

·      There is an Unload statement in the Paint event for the form or for a control on the form that has the Paint event.

Remove the Unload statement from the Paint event.

·      There is an Unload statement in the Change, Click, or DropDown events of a ComboBox.

Remove the Unload statement from the event.

·      There is an Unload statement in the Scroll event of an HScrollBar or VScrollBar control.

Remove the Unload statement from the event.

·      There is an Unload statement in the Resize event of a Data, Form, MDIForm, or PictureBox control.

Remove the Unload statement from the event.

·      There is an Unload statement in the Resize event of an MDIForm that is trying to unload an MDI child form.

Remove the Unload statement from the event.

·      There is an Unload statement in the RePosition or Validate event of a Data control.

Remove the Unload statement from the event.

·      There is an Unload statement in the ObjectMove event of an OLE Container control.

Remove the Unload statement from the event.

Regards
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Expert Comment

by:kamall
Comment Utility
Possible solution:
Put a timer on your form, set its Interval property to 100, and set its Enabled property to False, and use this code (your code modified):

Option Explicit
      Public Intx As Integer
      Public d, z As Integer
      Public Frst As Integer

Private Sub cboTest_Click()

    Timer1.Enabled = True

End Sub

      Private Sub cmdStop_Click()
      End
      End Sub

      Private Sub Command1_Click()

      For d = 1 To z
          Load imgTest(d)
          imgTest(d).Height = 615
          imgTest(d).Width = 615
          imgTest(d).Top = 615
          imgTest(d).Left = (615 * d)
          imgTest(d).Visible = True
      Next
      End Sub

      Private Sub Command2_Click()
      For d = 1 To z
          Unload imgTest(d)
          Intx = Intx - 1
      Next
      Frst = 1
      End Sub

      Private Sub Form_Load()
      z = 5
      Frst = 1
      End Sub
      Private Sub unloadarray()

      For d = 1 To z
          Unload imgTest(d)
          Intx = Intx - 1
      Next
      End Sub

Private Sub Timer1_Timer()
     
      Timer1.Enabled = False
      If Frst = 0 Then
          unloadarray
      End If
      Frst = 0
      For d = 1 To z
          Load imgTest(d)
          imgTest(d).Height = 615
          imgTest(d).Width = 615
          imgTest(d).Top = 615
          imgTest(d).Left = (615 * d)
          imgTest(d).Visible = True
      Next

End Sub

0
 

Author Comment

by:MaryD
Comment Utility
I will try what you suggested. My co-worker and I discovered that if we changed the combo box to a list box the code works like we expect to also.
0
 
LVL 7

Expert Comment

by:kamall
Comment Utility
Yes. The list box does not have problem.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now