list作为参数的函数问题
主要功能是从list控件中取出所选中的内容,存入数组中供其他过程使用
Public Function arry(lst As ListBox) As String
Dim i As Integer
Dim j As Integer
Dim m As Integer
Dim n As Integer
j = 0
m = lst.SelCount
n = lst.ListCount
ReDim arry(m - 1) 此处是否可以重新定义,调试中出错,怀疑是这个问题
For i = 0 To n - 1
If lst.Selected(i) Then
arry(j) = lst.List(i)
j = j + 1
End If
Next i
End Function
[解决办法]
Public Function arry(lst As ListBox) As Variant Dim i As Integer Dim j As Integer Dim m As Integer Dim n As Integer Dim arr() j = 0 m = lst.SelCount n = lst.ListCount ReDim arr(m - 1) ' 此处是否可以重新定义,调试中出错,怀疑是这个问题 For i = 0 To n - 1 If lst.Selected(i) Then arr(j) = lst.List(i) j = j + 1 End If Next i arry = arr End FunctionPrivate Sub Form_Load()For i = 0 To 10List1.AddItem iNextEnd SubPrivate Sub List1_Click()Dim aa = arry(List1)For i = 0 To UBound(a)MsgBox a(i)NextEnd Sub