将单词 'and' 添加到消息框中的列表

Adding the word 'and' to a list in a message box

我需要帮助开始编写代码,以便在用户从列表框中选择项目后将单词 'and' 添加到消息框以使消息框在语法上正确。也可能删除最后一个逗号。

Private Sub cmdSelect_Click()
Dim IntIndex As Integer, strSelectedHHItems As String
For IntIndex = 0 To lstHouseHoldItems.ListCount
    If lstHouseHoldItems.Selected(IntIndex) Then
        strSelectedHHItems = strSelectedHHItems & "," & " " & lstHouseHoldItems.Column(0, IntIndex)
    End If
Next
strSelectedHHItems = Right(strSelectedHHItems, Len(strSelectedHHItems) - 1)'remove beginning space
MsgBox "You have selected" & (strSelectedHHItems)
End Sub

我是业余爱好者,我知道这需要使用一些内部函数,例如 Mid 或 Len,但我想不出该怎么做。非常感谢您的帮助。

知道最后一个逗号的位置后,只需将新字符串串起来即可:

loc = InStrRev(strSelectedHHItems, ",")
strSelectedHHItems = Mid(strSelectedHHItems, 1, loc - 1) & " and " & Mid(strSelectedHHItems, loc + 2)