Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unload command being sketchy for control array

Status
Not open for further replies.

Fion

Vendor
Sep 25, 2003
50
0
0
US
Hi all, I am having an odd problem with objects in a control array. I can load then fine, but for some reason, I cannot call the unload command where I want to. I have a combobox where, when the user selects "End" all of the control array components beyond that unload. But, when I try to do that, I get a "unable to unload within this context" error. Just for grins, I made a test button with only the unload command in it, and that works fine... it is exactly the same command? Can anyone see what I am missing here? Below is the code of the components in question:

----------------------------------------------
Private Sub Andor_Click(I As Integer)
Dim X As Integer
If (Andor(I).Text = "And") Or (Andor(I).Text = "Or") Then
If (I = Conditions) And (Conditions < 5) Then
Loading con(I + 1), I
Fillcon con(I + 1)

Loading Eqnoteq(I + 1), I
Filleq Eqnoteq(I + 1)

Loading Group(I + 1), I
FillGroup Group(I + 1)

Loading Lab(I + 1), I
Filllab Lab(I + 1)

Loading Loc(I + 1), I
Filllocation Loc(I + 1)

Loading Size(I + 1), I
FillSize Size(I + 1)

Loading Andor(I + 1), I
FillAO Andor(I + 1)

Loading Sysarc(I + 1), I
Filllab Sysarc(I + 1)

Loading Smlabel(I + 1), I
Loading Criti(I + 1), I
Loading smcriti(I + 1), I

Conditions = Conditions + 1
Con_Click (I + 1)
End If
Else
If (Andor(I).Text = "End") And (Conditions > 1) And (Conditions > I) Then
For X = Conditions To (I + 1)
Unload con(X)
Unload Eqnoteq(X)
Unload Group(X)
Unload Lab(X)
Unload Loc(X)
Unload Size(X)
Unload Andor(X)
Unload Sysarc(X)
Unload Smlabel(X)
Unload Criti(X)
Unload smcriti(X)
Next X
Conditions = I
End If
End If
End Sub
---------------------------------------------
Private Function Loading(ByRef CB, I)
Load CB
CB.Top = CB.Top + (360 * I)
CB.Visible = True
End Function
---------------------------------------------
Private Sub Com_Click(I As Integer)
Unload con(Conditions)
End Sub
---------------------------------------------
the Com_click is the on that works fine... there are no parent-child relationships here, and everything is on the same form and all that...
Anyone see any problems, or have any ideas?

Fion
 
It looks like your pre-tests only allow the last set to be removed.:

If .... And (Conditions > I) Then
For X = Conditions To (I + 1)



________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

Essex Steam UK for steam enthusiasts
 
Unload commands are not permitted in the click event of a combobox, or any code that is called as a result of the click event.

There's also several other places where unload is not allowed. please see this link:



Now you may say, "That's all well and good, but how do I fix my problem?"

Well, I know of two ways. One is to set a global control variable, enable a timer, and then have the timer unload the control. With a interval time set very short, it should happen right after the click event is exited ( as long as you don't have a DoEvents in the click event. )

The other way is to use a list box for your data instead of a combo box. You can unload from a click event of a listbox. If you need a "drop down" effect, you can always use a listbox, a text box and a command button to create a resonable facimile of a drop down combo.

Robert
 
Awesome, I used the timer control, and it works perfectly, Thanks a million!
Although on thing, the unload event DOES work in response to a click event of a normal button... just FYI
Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top