Using For i = olSourceFolder.Items.Count To 1 Step -1??

  • Thread starter Thread starter Skip9999999999
  • Start date Start date
S

Skip9999999999

Guest
Thanks to many of you, I have developed a VB.net program to read and parse Outlook 2016 Mail Items, move them to a completed folder and create a tab delimited file for each item to be picked up and used by another program. Considering I knew nothing about programing or vb.net I'm pretty happy with it BUT...

I'm using a For Next statement to read each mail item in the Inbox. My concern is that new emails are constantly coming in which would "seem" to throw off the 'i' value. Yet in all my testing, by adding new mail item to the inbox after the value of 'i' is set, all the items, even the added ones get processed. (I add new mail items by placing a break in the code and adding the items while program in paused.) Maybe I'm worried about nothing but this just does not seem right and I don't want the program to blow up once in production. Any comments or suggestions??

Here is a bit of the code:

For i = olSourceFolder.Items.Count To 1 Step -1
Try
mi = TryCast(mi, Outlook.MailItem)
mi = olSourceFolder.Items(i)

'Parse out the eCommerse Cart Order Number
subject = mi.Subject
emailBody = mi.Body

'Parse each Email Line
Dim emailBodyLines As String() = emailBody.Split(separators, StringSplitOptions.RemoveEmptyEntries) ' an array to hold each 'line' of the email

……...do more parsing

Next ' Get next email




Carl

Continue reading...
 
Back
Top