?
Solved

another control array question - BergJC

Posted on 1998-10-23
6
Medium Priority
?
143 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
[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
  • 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 100 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

765 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