【发布时间】:2012-12-11 14:12:26
【问题描述】:
代码
height = objExcel1.Application.WorksheetFunction.CountA(ob3.Columns(1))
'MsgBox(height)
ReDim dataArray(height - 2, 0) ' -1 for 0 index, -1 for the first row as header row, excluded
str = ""
dataArray = ob3.Range(ob3.Cells(2, 1),ob3.Cells(height, 1)).Value
Set d = CreateObject("scripting.dictionary")
'MsgBox(LBound(DeletArr) & ":" & UBound(DeletArr))
For i = LBound(DeletArr) To UBound(DeletArr)
If Not d.exists(DeletArr(i)) Then
d(DeletArr(i)) = 0
End If
Next
MsgBox(LBound(dataArray,1) & ":" & UBound(dataArray,1))
For i = LBound(dataArray, 1) To UBound(dataArray, 1) - 1
If d.exists(dataArray(i, 1)) Then
str = str & (i+1) & ":" & (i+1) & ","
'ob3.Range(i & ":" & i).Delete
Else
'found = False
End If
Next
VBScript 数组是基于 0 的。但是为什么LBound(dataArray,1) 给出的起始下标是1,为什么不是0? Ubound 给出了数字 - 我有点困惑是数组的最后一个下标还是大小?
谢谢,
【问题讨论】:
-
圣诞快乐!如果您希望数组从零开始,请添加
option base 0:) 让我为您提供一个测试代码。 -
@bonCodigo 圣诞快乐!祝你,希望你和你的家人享受一整天!
-
@bonCodigo 好的!我相信你的话!但是 Ubound() 返回的数字是它的最后一个下标还是该数组中的元素总数?也请确认。由于这个概念,我的脚本会导致数据丢失!!
-
你能告诉我你在哪里有丢失数据的问题吗?如果您参考我们提供给您的大多数示例代码,则使用
Transpose方法从 Range 对象填充数组。 -
@bonCodigo 我基本上受过 C、C++、java、oracle 的教育——在哪个平台上我从未见过这样的场景!但它的好运气数据丢失帮助我知道了这个因素!现在我需要真正去每个脚本,需要检查哪些是按范围分配的,需要设置循环不是
lboundas0而是1和Ubound不是ubound-1而是@987654332 @!!!呵呵,上帝救救我:-)