拆分字符串并输出到 MS Access 2007 中的列表框

发布于 2024-12-02 05:22:58 字数 217 浏览 0 评论 0原文

如果我有一个文本框,其内容类似于“大棕色狐狸跳过了懒狗”, 我如何分割它并将内容放入这样的列表框中:

0,the

1,big

2,brown

3,fox

4,jumped

5,over

6,the

7,lazy

8,dog

PLz帮助,新手

if i have a textbox with contents like "the big brown fox jumped over the lazy dog",
how do i split it and put the contents in a listbox like this:

0,the

1,big

2,brown

3,fox

4,jumped

5,over

6,the

7,lazy

8,dog

PLz help, newbie

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2024-12-09 05:22:58

您可以使用 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" 可以;0";1"如果您希望隐藏第一列(尽管如果您不更改默认属性,它将是绑定列),您还需要将 RowSourceType 属性设置为“值列表”,

但需要注意的是:

有一个硬性限制。关于 Rowsource 的长度属性,当它是一个值列表时,我不记得确切的数字,但它超过 2000 个字符,如果您需要更多,那么我建议您将创建列表的代码转换为自定义函数。有关如何在组合/列表框的帮助中执行此操作的说明。

You could use the Split() function. Something like this:

  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

Now, you'd then need a listbox defined with two columns, and you'd want to set the widths on those columns appropriately (0.5";1" works if you want to see both; 0";1" works if you want the first column to be hidden (though it will be the bound column if you don't change the default properties). You also need to set the RowSourceType property to "Value List".

One caveat:

There's a hard limit on the length of the Rowsource property when it's a Value List. I can't remember the exact number, but it's somewhere upward of 2000 characters. If you need more than that, then I'd suggest you convert the code that creates the list to a custom function. There are instructions on how to do this in the help for combo-/listboxes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文