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个字符。如果你需要更多,那么我建议你将创建列表的代码转换为自定义函数。有关于如何在组合/列表框帮助中执行此操作的说明。
我完全按照你所说的使用它,它完美地工作。谢谢大卫。 –