0
如果我有一個像「大棕狐狸跳過懶狗」內容的文本框, 如何分割它,並把內容放入這樣的列表框中:分裂一個字符串和輸出到ms訪問2007中的列表框
0時,
1,大
2,褐色
3,狐狸
4,躍升
5,在
6,
7,懶惰
8,狗
plz幫助,新手
如果我有一個像「大棕狐狸跳過懶狗」內容的文本框, 如何分割它,並把內容放入這樣的列表框中:分裂一個字符串和輸出到ms訪問2007中的列表框
0時,
1,大
2,褐色
3,狐狸
4,躍升
5,在
6,
7,懶惰
8,狗
plz幫助,新手
你可以使用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個字符。如果你需要更多,那麼我建議你將創建列表的代碼轉換爲自定義函數。有關於如何在組合/列表框幫助中執行此操作的說明。
我完全按照你所說的使用它,它完美地工作。謝謝大衛。 –