Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the right procedure for a combo box

9 views
Skip to first unread message

kirk shirley

unread,
Mar 25, 2005, 11:10:08 AM3/25/05
to
Hi,
I'm trying to use a combo box but if I use dropdown for the procedure it
doesn't work right. I have the 4 items in the list of the comb box ok, but
as soon as you hit the down arrow this sub fires before you select one. And
Click for the procrdure is not correct either.
thanks
Kirk

Private Sub Combo1_DropDown(Index As Integer)
' choose between the com ports here
Dim PortSelect As Integer
PortSelect = Index

MSComm1.PortOpen = False
If PortSelect = 0 Then MSComm1.CommPort = 1
If PortSelect = 1 Then MSComm1.CommPort = 2
If PortSelect = 2 Then MSComm1.CommPort = 3
If PortSelect = 3 Then MSComm1.CommPort = 4
MSComm1.PortOpen = True

End Sub


Rick Rothstein

unread,
Mar 25, 2005, 11:57:38 AM3/25/05
to

You are going to have to give us some more information. You say the
Click event in "not correct" for what you are trying to do; but you
haven't told us what you are trying to do and WHY the Click event is not
working the way you want. How do you want the user interaction to work
if clicking on an item is not correct?

Rick - MVP

kirk shirley

unread,
Mar 25, 2005, 12:15:21 PM3/25/05
to
I thought the code was obvious.
Well, I'm just trying to select Com1, Com2, Com3 or Com4 with a Combo box.
When I use click as a procedure and put a break at PortSelect = Index, it
dosn't change. Index is always 0. Click will try to run the Sub but index is
not being changed. I want the user to click on the down arrow and select
the proper com port (com1 com2 com3 or com4) then I want the program to
change the MSComm1.Comm Port to change to the proper com port.
Kirk

Rick Rothstein <rickNOS...@NOSPAMcomcast.net> wrote in message
news:yZOdnZHga9W...@comcast.com...

AK

unread,
Mar 25, 2005, 12:18:18 PM3/25/05
to

"kirk shirley" <kirks...@hotmail.com> skrev i en meddelelse
news:Xr6dnTCM0JJ...@comcast.com...


The style property must be set to 2
Combo1.Style = 2
When using the Click event the Combo1.Text
returns the selected item.


Rick Rothstein

unread,
Mar 25, 2005, 12:26:15 PM3/25/05
to
> I thought the code was obvious.

Well, it wasn't... at least to me.<g>

> Well, I'm just trying to select Com1, Com2, Com3 or Com4 with a Combo
box.
> When I use click as a procedure and put a break at PortSelect = Index,
it
> dosn't change. Index is always 0. Click will try to run the Sub but
index is
> not being changed. I want the user to click on the down arrow and
select
> the proper com port (com1 com2 com3 or com4) then I want the program
to
> change the MSComm1.Comm Port to change to the proper com port.

Do you have more than one ComboBox arranged in a control array? I ask
because that is what the "Index As Integer" parameter means on all of
your ComboBox event procedures. In any event (no pun intended), for what
you are describing you want to do, try using this line instead

PortSelect = Combo1(Index).ListIndex

if you have a deliberate control array of ComboBoxes. If you only have
one ComboBox named Combo1, then remove the value you placed in that
ComboBox's Index property at design-time and use this line instead

PortSelect = Combo1.ListIndex

Anyway, it is the ListIndex property of the ComboBox that identifies the
"index" of the item selected by the user. Oh, and you will want to be
using the Click event for your code.

Rick - MVP

Steve Gerrard

unread,
Mar 25, 2005, 12:28:58 PM3/25/05
to

"kirk shirley" <kirks...@hotmail.com> wrote in message
news:eP2dnezrON-...@comcast.com...

>I thought the code was obvious.
> Well, I'm just trying to select Com1, Com2, Com3 or Com4 with a Combo box.
> When I use click as a procedure and put a break at PortSelect = Index, it
> dosn't change. Index is always 0. Click will try to run the Sub but index is
> not being changed. I want the user to click on the down arrow and select
> the proper com port (com1 com2 com3 or com4) then I want the program to
> change the MSComm1.Comm Port to change to the proper com port.
> Kirk
>

The index is an indicator of which combobox in a control array has been clicked,
not which item in the list has been selected.

Try this in the Click event:

PortSelect = Combo1(Index).ListIndex

kirk shirley

unread,
Mar 25, 2005, 1:54:34 PM3/25/05
to
That was it. Thanks again
Kirk

Rick Rothstein <rickNOS...@NOSPAMcomcast.net> wrote in message

news:U9ydnc7q_M4...@comcast.com...

AK

unread,
Mar 25, 2005, 2:51:08 PM3/25/05
to
' You don't need the If..Then clause,
' if you load your ComboBox with the portNumbers
' in the formLoad or Sub Main. And uses the Combos
' text property instead of listIndex property.

Private Sub command1_Click()
For i = 1 To 4
Combo1.AddItem i
Next
End Sub

Private Sub Combo1_Click()
MSComm1.CommPort = Combo1.Text
End Sub


kirk shirley

unread,
Mar 28, 2005, 2:23:20 PM3/28/05
to
It worked for a while but,
after recovering from a bad save and rebuilding, I get :

"procedure declaration does not match description of event or procedure
having the same name".

Private Sub Combo1_Click(Index As Integer)
PortSelect = Combo1(Index).ListIndex


MSComm1.PortOpen = False
If PortSelect = 0 Then MSComm1.CommPort = 1
If PortSelect = 1 Then MSComm1.CommPort = 2
If PortSelect = 2 Then MSComm1.CommPort = 3
If PortSelect = 3 Then MSComm1.CommPort = 4
MSComm1.PortOpen = True
End Sub


Kirk


0 new messages