|
楼主 |
发表于 2016-1-9 12:14
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
11、显示数组/字典内容函数
此函数方便随时显示数组或字典的内容,可在程序最后显示数组数据,可在程序执行过程中及程序调试时显示数组数据,使数组内容感性化,提高代码调试效率。
Public Function 显示数组(arr, flag, ParamArray Other())
Rem 显示数组连续行或非连续行内容,显示字典键和值的内容
Rem 参数1为数组或字典名称,参数2(1为显示连续区域,后面有起止两个参数;2为显示不连续行,后面参数不确定),参数2后面至少要有两个参数。字典名称后也要有两个参数
Dim brr(), str, r, c, i, max, k, it, max1, max2
If TypeName(arr) = "Dictionary" Then
ReDim brr(1 To 2)
k = arr.keys: it = arr.items
For i = 0 To UBound(k)
brr(1) = Application.max(Len(k(i)), max1)
brr(2) = Application.max(Len(k(i)), max2)
Next
For i = 0 To UBound(k)
str = str & i + 1 & Chr(9) & k(i) & Space(brr(1) - Len(k(i))) & Chr(9) & it(i) & Space(brr(2) - Len(it(i)))
str = str & Chr(10)
Next
Else
ReDim brr(1 To UBound(arr, 2))
For c = 1 To UBound(arr, 2)
For r = 1 To UBound(arr)
max = Application.max(Len(arr(r, c)), max)
Next
brr(c) = max: max = 0
Next
If flag = 1 Then
For r = Other(0) To Other(1)
For c = 1 To UBound(arr, 2)
str = str & IIf(c = 1, r & Chr(9), Chr(9)) & arr(r, c) & Space(brr(c) - Len(arr(r, c)))
Next
str = str & Chr(10)
Next
Else
For r = 0 To UBound(Other)
For c = 1 To UBound(arr, 2)
str = str & IIf(c = 1, Other(r) & Chr(9), Chr(9)) & arr(Other(r), c) & Space(brr(c) - Len(arr(Other(r), c)))
Next
str = str & Chr(10)
Next
End If
End If
显示数组 = str
End Function |
|