2 Replies - 2101 Views - Last Post: 10 December 2012 - 02:30 AM Rate Topic: -----

#1 kfish   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-December 12

Parallel For Loop

Posted 10 December 2012 - 01:43 AM

I have a parallel for loop which loops though an array of XML and replaces a tag (<Scheme Ref="Temp_Scheme"/>) whith a tag passed into the sub routine.

 
        Parallel.For(LBound(Input_Array), UBound(Input_Array), Sub(i)
                                                                   lngStart = InStr(1, Input_Array(i), "<Scheme Ref=""", CompareMethod.Binary)
                                                                   lngEnd = InStr(lngStart, Input_Array(i), "</Schemes>", CompareMethod.Binary)
                                                                   strOld = Mid(Input_Array(i), lngStart, lngEnd - lngStart)
                                                                   Input_Array(i) = Replace(Input_Array(i), strOld, Scheme_Ref, 1, 1)
                                                               End Sub)



The loops works fine for the first 49 entires in the array but for some reason doesn't make the replacement for the 50th entry (the last entry in the array), as a normal for loop the tag is changed as expected.

Am I missing anything?

Is This A Good Question/Topic? 0
  • +

Replies To: Parallel For Loop

#2 lucky3   User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 233
  • View blog
  • Posts: 770
  • Joined: 19-October 11

Re: Parallel For Loop

Posted 10 December 2012 - 02:02 AM

Parallel.For takes second argument as exclusive end index. Ubound returns last valid index in array. So if you have array with 7 elements, it will return 6, because myArray(6) as Integer could hold 7 elements: {1,2,3,4,5,6,7}. Parallel.For would in that case take a 6 as exclusive end index, and will actually loop 6 times if first parameter is 0 (0,1,2,3,4,5). With other words: take Input_Array.Length as second parameter in your case.
Was This Post Helpful? 1
  • +
  • -

#3 kfish   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-December 12

Re: Parallel For Loop

Posted 10 December 2012 - 02:30 AM

Thanks Lucky that's cleared it right up!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1