arrays - 使用单指令填充 VB6 列表框

标签 arrays vb6 listbox

在 VB6 中我似乎无法做到这一点:

myListBox.List = listContentStringArrray

VB 提示编译错误“参数不可选”,显然是因为 .List(index) 需要一个索引。

以下代码可在 VBA 中运行:

Private Sub CommandButton1_Click()
    Dim result() As String
    ReDim result(0)
    result(0) = "hello"
    ReDim Preserve result(1)
    result(1) = "world"

    ListBox1.List = result

End Sub

查看对象浏览器我发现VBA中的ListBox实际上是MSForms.ListBox,而在VB6中它是VB.ListBox

VBA ListBox 的 List 属性声明为 Property List([pvargIndex], [pvargColumn]),在 VB6 中它是 Property List(Integer) As String ,这就是我的问题所在。

有没有办法在现有代码库中“交换”VB.ListBoxMSForms.ListBox而不破坏任何东西,或者MSForms设计为仅在 VBA 中使用,因为“VB”库不包含在 VBA 中?如果我在 VB6 项目中引用 FM20.dll,我可以在对象浏览器中看到 MSForms.ListBox,但在工具箱中看不到。

最佳答案

可以在 VB6 应用程序中使用 Forms 2.0 控件。例如,它是获取支持 Unicode 的控件的方法之一(请参阅 How To Read and Display UNICODE String on Visual Basic Form 知识库文章)。

If I reference FM20.dll in my VB6 project, I can see the MSForms.ListBox in the object browser, but not in the toolbox.

要将控件添加到工具箱,您必须通过Project | 添加Microsoft Forms 2.0 对象库组件菜单项 (Ctrl+T): enter image description here

但是,坦率地说,如果您需要的只是“用单条指令填充 VB6 ListBox”的能力,那就有点大材小用了。只需编写一个例程来为常规 VB6 ListBox 执行此操作即可。

另请记住,Forms 2.0 控件不可可重新分发。来自 INFO: Usage and Redistribution of FM20.DLL知识库:

The Fm20.dll is NOT redistributable. You must have an application such as Microsoft Office 97 on the target system that installs Fm20.dll as part of its setup... In any case, you may not distribute the Fm20.dll as part of your setup, even if you purchase the Microsoft Office Developer Edition product.

As an alternative to having your end users install Microsoft Office, you can have them freely download and install the Microsoft ActiveX Control Pad, which also installs the Fm20.dll.

关于arrays - 使用单指令填充 VB6 列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16442495/

相关文章:

constructor - VB 中构造函数的正确语法?

VB6 默默地从表单中删除大量控制数据

c - C中整数的特定数字计数

arrays - 普通数组与可分配/指针数组,Fortran 建议?

php - 使用 PHP 将 MySQL 表中的数组内容分成多行

javascript - 在 JavaScript 中比较 2 个数组

javascript - 如何以编程方式更改此下拉菜单中的所选项目?

c# - ListBox Shift-Click Multi-Select Anchor 设置不正确

c# - 如何获取列表框中的项目数

html - 单选 HTML 列表框高度