Solved

another control array question - BergJC

Posted on 1998-10-23
6
138 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 add a minute to the date time value 8 60
MS SQL store procedure to calculate and return result 6 49
Add and format columns in vb6 7 42
Child Form in front 4 34
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…
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…
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…
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…

948 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

19 Experts available now in Live!

Get 1:1 Help Now