Maximum index on a list is less than the list size

P

Parag

I keep getting "Make sure that the maximum index on a list is less
than the list size" on the line "olItem.Subject = vInfo(1)" - any
clues on what the issue maybe?

This is a very simple app that's supposed to invoke a new Outlook
email message, break the command line output using "|" delimiter and
feed it into the To, Subject and Body fields of the email
respectively.

Module SendEmail

Public Sub Main()

Dim myOleApp As Microsoft.Office.Interop.Outlook.Application
Dim olItem As Microsoft.Office.Interop.Outlook.MailItem
Dim vInfo As Array

' Assume Command line parameter is text separated by "|"
vInfo = Split(Command, "|")

' Create Outlook instance and a mail item
myOleApp = New Microsoft.Office.Interop.Outlook.Application
olItem =
myOleApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)

' Fill in To, Subject and Message
olItem.To = vInfo(0)
olItem.Subject = vInfo(1)
olItem.Body = vInfo(2)

'Actually send the email
olItem.Send()

' Tidy up
olItem = Nothing
myOleApp = Nothing

End Sub

End Module
 
F

Family Tree Mike

I keep getting "Make sure that the maximum index on a list is less
than the list size" on the line "olItem.Subject = vInfo(1)" - any
clues on what the issue maybe?

This is a very simple app that's supposed to invoke a new Outlook
email message, break the command line output using "|" delimiter and
feed it into the To, Subject and Body fields of the email
respectively.

Module SendEmail

Public Sub Main()

Dim myOleApp As Microsoft.Office.Interop.Outlook.Application
Dim olItem As Microsoft.Office.Interop.Outlook.MailItem
Dim vInfo As Array

' Assume Command line parameter is text separated by "|"
vInfo = Split(Command, "|")

' Create Outlook instance and a mail item
myOleApp = New Microsoft.Office.Interop.Outlook.Application
olItem =
myOleApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)

' Fill in To, Subject and Message
olItem.To = vInfo(0)
olItem.Subject = vInfo(1)
olItem.Body = vInfo(2)

'Actually send the email
olItem.Send()

' Tidy up
olItem = Nothing
myOleApp = Nothing

End Sub

End Module

It means there are no "|" in the input string to the split command.
Perhaps vInfo is only dimensioned to 1, so the only accessible item is
vInfo (1).

Note, if there is one "|" in the input string, you would get the error
referencing vInfo (2). You should check the dimension of vINfo before
using the data in it.
 
F

Family Tree Mike

Family Tree Mike said:
It means there are no "|" in the input string to the split command.
Perhaps vInfo is only dimensioned to 1, so the only accessible item is
vInfo (1).

Sorry, if it is dimensioned to 1, then vInfo(0) is the only accessible item.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top