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
Solved

another control array question - BergJC

Posted on 1998-10-23
6
140 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
ID: 1441338
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
ID: 1441339
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
ID: 1441340
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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 7

Expert Comment

by:kamall
ID: 1441341
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
ID: 1441342
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
ID: 1441343
Yes. The list box does not have problem.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

791 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