2011-09-01 66 views

回答

1

你可以使用Split()函數。事情是這樣的:

Public Function SplitToListBox(ByVal strInput As String) As String 
    Dim strTemp() As String 
    Dim intCounter As Integer 
    Dim strRowsource As String 
    Const strQuote As String = """" 

    strTemp() = Split(strInput, " ") 
    For intCounter = 0 To UBound(strTemp()) 
     If Len(strRowsource) = 0 Then 
     strRowsource = strQuote & Trim(CStr(intCounter)) & strQuote & "; " & strQuote & strTemp(intCounter) & strQuote 
     Else 
     strRowsource = strRowsource & "; " & strQuote & Trim(CStr(intCounter)) & strQuote & "; " & strQuote & strTemp(intCounter) & strQuote 
     End If 
    Next intCounter 
    SplitToListBox = strRowsource 
    End Function 

現在,你再需要兩列定義一個列表框,和你想設置適當這些列的寬度(0.5「1」的作品,如果你想看到both; 0「; 1」如果您希望隱藏第一列(儘管如果您不更改默認屬性,它將成爲綁定列),您還需要將RowSourceType屬性設置爲「值列表」。

警告:

有就當它是一個值列表我不記得確切的數字的行來源屬性的長度的硬性限制,但它的某處向上的2。 000個字符。如果你需要更多,那麼我建議你將創建列表的代碼轉換爲自定義函數。有關於如何在組合/列表框幫助中執行此操作的說明。

+0

我完全按照你所說的使用它,它完美地工作。謝謝大衛。 –