• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

Unload Error

I have an array of a couple of sliders and checkboxes on a VB6 form. I created them dynamically (programatically) using this code:

For i = 1 to 10
    Load Slider1 (i)
    Load CheckBox1 (i)
Next i

The problem comes in when I try to unload the controls. I start from the highest indexed one (10) and make my way down:

For i = Slider1.UBound To 1 Step -1
    Unload Slider1 (i)
    Unload CheckBox1 (i)
Next i

As soon as it executes the first loop, I get this error message:

Run-time Error '365':
Unable to unload within this context.

Any ideas?
  • 2
1 Solution

Are you trying to unload the sliders from within the click event of on of the slider controls? This is a rare problem but there are certain controls that cannot be unloaded from within certain events. If you cannot change the event from which it is being unloaded then the only solution ( a bit of a kludge really ) is to add a timer control and fire this a very short period after the event finishes. This will then allow you to unload the controls.

Tim Cottee
SETPAuthor Commented:
I'm unloading them from the click event of a ComboBox. It's not a normal slider though - it's an xFxSlider from xFxJumpStart, but it has the exact same problem with the checkbox (standard Windows checkbox) and Label (standard Windows Label)...
SETPAuthor Commented:
WOW!!! Apparently you cannot unload controls from the Change, Click, or DropDown events of a ComboBox! What the hell??? Why on earth not??? Here is the full list if events you cannot unload controls from:

the Paint event for the form or for a control on the form that has the Paint event.
the Change, Click, or DropDown events of a ComboBox.
the Scroll event of an HScrollBar or VScrollBar control.
the Resize event of a Data, Form, MDIForm, or PictureBox control.
the Resize event of an MDIForm that is trying to unload an MDI child form.
the RePosition or Validate event of a Data control.
the ObjectMove event of an OLE Container control.


There's also a thread on Experts-Exchange from someone who had the same problem but noone could explain to him why Microsoft put these restrictions in Visual Basic 6.

Thanks for you help TimCottee

Featured Post

Industry Leaders: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now