arrays - 如何将列表框中的项目写入数组 VBA
问题描述
在用户表单中,我希望CommandButton1_Click
基本上将列表框中的任何内容放入我设置的数组中As Variant
。ComandButton2_Click
获取用户在 ComboBox 中选择的任何内容并将其插入 ListBox。但是我正在用我想要带走的最后一个数组来做这个SelectedTitles
。
Public SelectedTitles As Variant, ArrCount As Long, EnableEvents As Boolean
Private Sub CommandButton1_Click()
Dim Size As Integer
Size = ListBox1.ListCount - 1
ReDim SelectedTitles(0 To Size) As Variant
Dim x As Integer
For x = 0 To Size
SelectedTitles(x) = ListBox1.Value(x)
Next x
'Done Button
Me.Hide
End Sub
Private Sub CommandButton2_Click()
'User has indicated they want to add the currently selected item to the list
If Not EnableEvents Then Exit Sub
If ArrCount = 0 Then 'First item, create the array
SelectedTitles = Array("")
Else
ReDim Preserve SelectedTitles(UBound(SelectedTitles) + 1) 'Next items, add one more space in the array
End If
ListBox1.AddItem (ComboBox1.Value)
'Increment the counter
ArrCount = ArrCount + 1
'Reset the checkbox and the combobox
EnableEvents = False
CommandButton2.Value = False
ComboBox1.Value = ""
EnableEvents = True
End Sub
我收到错误“类型不匹配”
SelectedTitles(x) = ListBox1.Value(x)
解决方案
推荐阅读
- tensorflow - 如何使用所有 cpu 核心在 keras 中训练模型
- python - 如何使用从小部件文本框中输入的单词来搜索数据框,然后使用 python、ipywidgets 显示搜索结果?
- powershell - Powershell - Active Directory 不返回属性值
- apache-flink - Flink DataStream API中与欺诈检测演示相关的一些问题
- swagger - NestJS swagger-ui-express 包在部署后丢失
- wiremock - 无法识别 Wiremock 占位符
- laravel - 检测从 Postman 发送的请求
- git - 在结构化的 github 存储库中创建和推送文件
- python - 如何使用熊猫从 csv 中的绝对路径导入数据?
- python - 使用 Talisman for Flask/Python 时,Liveness/Readiness Probes 失败