Solved

another control array question - BergJC

Posted on 1998-10-23
6
139 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

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