0

私が遭遇した深刻なシナリオで、スクリプトが完全に障害者になりました。これは次のとおりです。

On Error Resume Next

For IndexSearch = 0 To ArrayListTaskDetails.Count - 1 Step 4

    If ArrayListTaskDetails(IndexSearch + 5) <> "" Then

        ArrayListTaskDetails(IndexSearch + 2) = ArrayListTaskDetails(IndexSearch + 5)

    'Else

        'ArrayListTaskDetails(IndexSearch + 2) = DicForProcessEndDate.Item(ob9.Cells(RowCount,1))

    End If 

Next

If Err Then

    Err.Clear
    MsgBox(IndexSearch) '4
    ArrayListTaskDetails(IndexSearch + 2) = DicForProcessEndDate.Item(ob9.Cells(RowCount,1))
    MsgBox(ob9.Cells(RowCount,1)) '47166954
    MsgBox(DicForProcessEndDate.Item(47166954)) ' here i am getting its value
    MsgBox(DicForProcessEndDate.Item(ob9.Cells(RowCount,1))) ' here i didn't see any value for the key ob9.Cells(RowCount,1). Even "47166954" and ob9.Cells(RowCount,1) are same

End If

On Error GoTo 0

問題が何であるかを理解するのを手伝ってもらえますか?それが本当に問題であり、ここでアプローチを変更することによってそれを解決するのを手伝ってくれるなら。

編集

制御がエラー処理部分に行くArray out of rangeラインからのようにエラーが発生した場合、それは完璧ですが、カウントは。だけ増加します。= 0の場合、例外が発生し、Exceptionブロックでnotの値を取得しているとしましょう。なぜそうなのですか?教えてください!If ArrayListTaskDetails(IndexSearch + 5) <> ""IndexSearch4IndexSearchIndexSearch40

4

1 に答える 1

1

ob9.Cells(RowCount,1)文字列値を返している可能性があります。

試してみるとMsgBox(DicForProcessEndDate.Item(47166954))、に渡されるキーの数値がハードコーディングされていますDicForProcessEndDate

ディクショナリオブジェクトのkeyプロパティは47166954、と"47166954"を異なる値と見なします。1つは数値で、もう1つは文字列であるため、これは理にかなっています。

問題を回避するために、 Clng()でキーをラップすることにより、キーを数値に変換できます。そのようです:

MsgBox(DicForProcessEndDate.Item(clng(ob9.Cells(RowCount,1))))

または、文字列値を使用する場合は、Cstr()を使用できます。


編集:2番目の質問への回答:

あなたは無効な仮定をしています。VBScriptエラートラップは、ExcelVBAと同じようには機能しません。具体的には、のようなことはできませんOn Error goto ErrorCorrection

この行があるためOn Error Resume Next、エラーが発生したかどうかに関係なく、forループが続行されます。

暗示したように、forループを停止したい場合は、ロジックを次のように更新する必要があります。

For IndexSearch = 0 To ArrayListTaskDetails.Count - 1 Step 4
    If ArrayListTaskDetails(IndexSearch + 5) <> "" Then
        'Check to see if proceeding line caused an error
        If err then
            'Clear the error
            err.clear
            'Exit the loop
            exit for
于 2012-12-28T15:50:05.447 に答える