A serious scenario I have encountered and which is totally made my Script handicapped, which is as below:
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
Could you help me to understand what the issue is? If it really an issue and help me to resolve it by changing the approach here.
EDIT
When an error occurs as Array out of range from the line If ArrayListTaskDetails(IndexSearch + 5) <> "" the control goes to error handling part,That’s perfect but the IndexSearch count is increased by 4. Lets say when IndexSearch = 0,then an exception raised and in the Exception block I am getting IndexSearch value as for 4 not, 0 — why so? please tell me!
It is likely that
ob9.Cells(RowCount,1)is returning a string value.When you try
MsgBox(DicForProcessEndDate.Item(47166954))You have hard-coded a numeric value for the key passed toDicForProcessEndDate.The Dictionary Object’s key property considers
47166954and"47166954"to be different values. This makes sense because one is numeric and the other is a string.To avoid your issue, you can convert your key to a numeric value by wrapping it in Clng(). Like so:
Alternately, if you wanted to use the string value you could use Cstr()
Edit: In response to your second question:
You are making an invalid assumption. VBScript error trapping does not work the same as Excel VBA. Specifically, you cannot do something like
On Error goto ErrorCorrection.Because of the line
On Error Resume Nextyour for loop will continue regardless of whether an error has occurred.If you want to halt the for loop, like you implied you will need to update your logic to something like this: