Link to home
Start Free TrialLog in
Avatar of SETP
SETP

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SETP
SETP

ASKER

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)...
Avatar of SETP

ASKER

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.

(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbmsgldCantUnloadHere.asp)

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