根据列表框选择更改标签标题

Change Label Caption based on ListBox selection

根据用户在列表框中选择的内容更改标签名称的最佳方法是什么。 到目前为止我有这个:

Private Sub Label6_Click()
    Dim lItem As Long
    For lItem = 0 To ListBox1.ListIndex <> -1
        If ListBox1.Selected(lItem) = "AAA" Or "BBB" Then
            Me.Label6.Caption = "Select Graphite"
        Else
            Me.Label6.Caption = "Select Oil System"
        End If
    Next lItem
End Sub

不幸的是它不起作用,我错过了什么? 谢谢!

除非你的列表框是多选的,否则你不需要遍历它:

Private Sub Label6_Click()
    Dim lItem As Long
    lItem = ListBox1.ListIndex
    If lItem <> -1 then
        Select Case ListBox1.List(lItem)
            Case "AAA", "BBB"
                Me.Label6.Caption = "Select Graphite"
            Case Else
                Me.Label6.Caption = "Select Oil System"
        End Select
    End If
End Sub