Solved my own problem - and yes, this is my final answer.
Okay. At long last, the mystery has been solved. Sit down and make yourself comfortable, this takes a bit of explaining. I'll keep this simple for the new coders in the group.
My program creates most of its controls dynamically, at runtime. One of them is a combo box. Right after I create the combo box, I add an event to it to trap the SelectionChanged event.
Then I try to set the SelectedIndex of the combo box. Whoops. Crash.
Why?
Turns out that any subroutine triggered by the SelectionChanged event *must* have the Index and Value parameters. Perhaps this will explain better...
Sub App_Start
Form1.Show
AddComboBox( "Form1", "cmb", 10, 10, 120, 30 )
For i = 1 To 10
cmb.Add( "fred" & i )
Next
xi = 3
cmb.SelectedIndex = xi
Msgbox( "Count = " & cmb.Count & Chr(13) & "Selected Index = " & cmb.SelectedIndex )
AddEvent( "cmb", SelectionChanged, "wubba" )
End Sub
Sub wubba
show.Text = "" & cmb.Item( cmb.SelectedIndex )
End Sub
This program won't work. But make this one little change...
Sub wubba( Index, Value )
show.Text = "" & cmb.Item( cmb.SelectedIndex )
End Sub
And everything's good. See why?
When the SelectedIndex of the combo box is changed, it raises a SelectionChanged event. When that event is passed to the subroutine I specified, two parameters get sent along with it - Index and Value. The subroutine has to accept those two parameters, or else bad things happen.
If you create a combo box in the forms designer, and also add an event to that combo box in the designer, the subroutine will be created for you, parameters and all. That will show you the proper way for a subroutine to handle a SelectionChanged event.
Hopefully someone will find this useful.
:sign0098: