arrays - 使用类模块的列表框
问题描述
在 visual basic 6.0 中,我正在处理数组和列表框。我希望当我单击命令按钮时,所有字符串值都将显示在列表框中,因此我想使用类中的对象并在表单中调用它。我想知道如何将列表框的字符串值从类模块调用到表单。
我已经尝试过字符串数组,但仅用于消息框。我不知道如何使用列表框。我可以展示我所做的。我使用 class1 创建了一个方法 friendslist()。正如那里看到的,我使用了消息框,我想用文本替换它。然后在 command1_click() 中调用这些文本作为列表框的值
Dim friends(5) As String
friends(0) = "Anna"
friends(1) = "Mona"
friends(2) = "Marie"
friends(3) = "Kent"
friends(4) = "Jona"
friends(5) = "Fatima"
For a = 0 To 5
MsgBox "Your friends are: " & friends(a)
Next
End Sub
Private Sub Command1_Click()
Dim myfriends As New Class1
Call myfriends.friendslist
End Sub
这是我的预期输出
解决方案
您可以将 ListBox 作为参数传递给 friendslist() 方法。
' insert this code into Class1
Public Sub FriendsList(oList As ListBox)
Dim a As Long
Dim friends(5) As String
friends(0) = "Anna"
friends(1) = "Mona"
friends(2) = "Marie"
friends(3) = "Kent"
friends(4) = "Jona"
friends(5) = "Fatima"
oList.Clear
For a = LBound(friends) To UBound(friends)
oList.AddItem friends(a)
Next a
End Sub
' insert this code into form
Private Sub Command1_Click()
Dim oFriends As Class1
Set oFriends = New Class1
oFriends.FriendsList List1 ' instead of List1, type the actual name of ListBox control
Set oFriends = Nothing
End Sub
推荐阅读
- mysql - MySQL全文搜索结果微调
- next.js - NextJs torible 从 router.query 获取大字符串
- caching - 如何为 symfony5 redis 缓存池设置命名空间和项目过期时间
- python - 实现我自己的 OpenID 提供程序和客户端时出现问题
- matplotlib - 如何使用 matplotlib 在地图上绘制线段?
- fastlane - 将测试人员添加到 Google Play 封闭式测试轨道?
- json - 如何从 React 功能组件中的本地 JSON 文件中获取所有 JSON 对象?
- java - Java Spring 测试表单端点
- reactjs - Laravel & React,动态渲染
- kotlin - 在when语句的情况下调用成员函数?