2012-12-25 3 views
-1

Subscript out of range- ArrParent으로 오류가 발생하는 이유를 말해 줄 수 있습니까? 내가 MsgBox(Lbound(ArrParent))을 사용했을 때 - 그것은 1을주고, MsgBox(Ubound(ArrParent))을 사용했을 때 960을주었습니다. 그래서 아래의 라인에 나는 out of range 오류가 있습니다. 아래의 전체 코드를 찾기 Dic(ArrParent(Count))=Count+2 :내 VBScript 코드에서 "아래 첨자가 범위를 벗어남"오류가 발생했습니다

코드

Sub ParentPIDNumber(ArrParent,ob3,ob2,ob4) 

     Dim Dic,DicItems,Dickeys 
     Dim Count 

     Set Dic = CreateObject("Scripting.Dictionary") 

     Count=LBound(ArrParent) 
     'MsgBox(ArrParent(Count)) 
     Do Until Count > UBound(ArrParent) - 1 

      Dic(ArrParent(Count))=Count+2 'here Dictionary keys are holding the row numbers as their Items 

     Count=Count+1 
     Loop 

     ParentChildBinding Dic,ob3,ob2,ob4 

    End Sub 
    Sub FileredOpenProcessToDel(ob3,ob2,ob4) 

     Dim ColumnToFilter,TotalRows 
     Dim rngFilter,cel,str,rangesToRemove,x 
     Dim strToRemove : strToRemove = "" 
     Dim ArrParent 

     objExcel1.ScreenUpdating = False 
     objExcel1.Calculation = -4135 'xlCalculationManual 
     ColumnToFilter=objExcel1.Application.WorksheetFunction.CountA(ob4.Rows(1)) - 1 
     ob4.Range(ob4.Cells(1,ColumnToFilter),ob4.Cells(1,ColumnToFilter)).AutoFilter ColumnToFilter, "Open",,,True 

     'Dim rngFilter as Range 
     Set rngFilter = objExcel1.Application.Intersect(ob4.UsedRange,ob4.UsedRange.Offset(1),ob4.Columns(1)).SpecialCells(12)'xlCellTypeVisible 
      'MsgBox(rngFilter.Rows.Count) 
      REM Do While 1=1 
      REM 'Msgbox 
      REM Loop 
     'msgbox "Filtered range has " & rngFilter.Rows.Count & " rows." 
      str="" 
      For each cel in rngFilter 

       str = str & (cel.row) & ":" & (cel.row) & "," 

      Next 

        rangesToRemove = Split(str,",") 

        For x = UBOUND(rangesToRemove)-1 To LBOUND(rangesToRemove) Step -1 

         strToRemove = strToRemove & rangesToRemove(x) 

          If Len(strToRemove) > 200 then 

           ob4.Range(strToRemove).delete'str & rangesToRemove(x) & ":" & rangesToRemove(x) & "," 
           strToRemove = "" 

          Else 

           strToRemove = strToRemove & "," 

          End If 

        Next 
        If len(strToRemove) > 0 then 

         strToRemove = Mid(strToRemove, 1, Len(strToRemove) - 1) 
         'strToRemove = Left(strToRemove, Len(strToRemove) -1) 
         ob4.Range(strToRemove).delete 

        End If 

     ob4.AutoFilterMode = False 
     objExcel1.ScreenUpdating = True 
     objExcel1.Calculation = -4105 'xlCalculationAutomatic 

     TotalRows=objExcel1.Application.WorksheetFunction.CountA(ob4.Columns(1)) 
     'MsgBox(TotalRows) 
     ReDim ArrParent(TotalRows - 2) 
     ArrParent=ob4.Range("A2:" & "A" & TotalRows).Value 
     'Call to the subroutine 
     ParentPIDNumber ArrParent,ob3,ob2,ob4 

    End Sub 

여기 제발 도와주세요!

답변

2

그런 상황에서 할 수있는 최선의 방법은 오류를 찾아 낼 때까지 별도의 스크립트에 오류 코드를 추출하고 거기에서 실험 해 보는 것입니다. 내가 오류를 찾을 수 귀하의 경우에는

다음 스크립트 오류를 ​​제공하지 않습니다하지만 내가 실험 할 당신의 sourcearray이없는하지만 당신은 할 수 배열

ArrParent = Array(10, 20, 30) 
Count=LBound(ArrParent) 
Set Dic = CreateObject("Scripting.Dictionary") 
Do Until Count > UBound(ArrParent) - 1 
    Dic(ArrParent(Count))=Count+2 
    Count=Count+1 
Loop 
for each key in Dic 
    wscript.echo key & ":" & Dic(key) 
next 

'10:2 
'20:3 

의 마지막 요소를 건너 뜁니다 배열 변수를 반복하는 가장 좋은 방법이 될 수있는 count 변수가 필요하지 않은 경우, "for each"를 사용할 수있는 범위를 벗어난 인덱스를 가지지 않기 위해 이렇게 해보십시오.

Count = 1 
Set Dic = CreateObject("Scripting.Dictionary") 
for each element in ArrParent 
    Dic(element)=Count+2 
    Count = Count+1 
next 

for each key in Dic 
    wscript.echo key & ":" & Dic(key) 
next 
'10:3 
'20:4 
'30:5 
+0

귀하의 제안에 감사드립니다. 내가 그것을 시도하자! –

관련 문제