2011-09-01 62 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

我完全按照你所说的使用它,它完美地工作。谢谢大卫。 –