将单词“和”添加到消息框中的列表中

问题描述 投票:0回答:1

在用户从列表框中选择项目以使消息框在语法上正确无误之后,我需要帮助在代码上添加单词“ 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

Message box needs to read Chair, Couch **AND** Nighstand.

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

vba ms-access msgbox
1个回答
0
投票

一旦知道了最后一个逗号的位置,只需将新字符串串在一起:

loc = InStrRev(strSelectedHHItems, ",")
strSelectedHHItems = Mid(strSelectedHHItems, 1, loc - 1) & " and " & Mid(strSelectedHHItems, loc + 2)
© www.soinside.com 2019 - 2024. All rights reserved.