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
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
Rick Rothstein <rickNOS...@NOSPAMcomcast.net> wrote in message
news:yZOdnZHga9W...@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.
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
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
Rick Rothstein <rickNOS...@NOSPAMcomcast.net> wrote in message
news:U9ydnc7q_M4...@comcast.com...
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
"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