-
I need to check if the user's name has been added into a listbox. As soon as it is I need to change the user form's caption to display the correct status.
Code:
If lstConnections.AddItem = txtName.Text Then
frmMain.Caption = "SmallTalk - Now Serving"
End If
This is the code I thought would work, but actually it stirs the following error, "Compile error - Argumant not optional."
Why did I get this error and How will I be able to check for the user's name added to the listbox in order to be able to set the correct status for the form's caption?
-
AddItem is used to add items. Use List(indexnro) instead.
List(0) for first item, List(1) for second etc.
You can check number of items with ListIndex. Remember that last List item is List(ListCount - 1).
ListIndex tell you which one of the items is selected.
Hope this helps,
-
hi
not sure.... but u may be able to use the "Instr" function to check if what u have in txtname.text is in lstConnections
hope that give u another option!!
Sanj
-
<?>
'if you load the caption when you load the name you
'don't have to check
'ie. list1.additem text1.text
'frmWhat.Caption = What
'I don't see as you need to check but if you want to
Code:
Option Explicit
'this can be any event you load the listbox from
Private Sub Command1_Click()
List1.AddItem Text1.Text
List1_ItemCheck (List1.ListCount - 1)
End Sub
Private Sub List1_ItemCheck(Item As Integer)
List1.ListIndex = List1.ListCount - 1
If List1.Text = Text1.Text Then
If lstConnections.AddItem = txtName.Text Then
frmMain.Caption = "SmallTalk - Now Serving"
End If
End If
End Sub