Home All Groups Group Topic Archive Search About

Maximum index on a list is less than the list size

Author
26 May 2010 2:36 AM
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

Author
26 May 2010 3:08 AM
Family Tree Mike
On 5/25/2010 10:36 PM, Parag wrote:
Show quoteHide quote
> 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.

--
Mike
Author
26 May 2010 5:45 AM
Fred
"Family Tree Mike" <FamilyTreeM***@ThisOldHouse.com> a écrit dans le
message de groupe de discussion :
OnmnFDI$KHA.***@TK2MSFTNGP02.phx.gbl...
> On 5/25/2010 10:36 PM, Parag wrote:

>> 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?

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

> 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).

Isn't «|» a separator for commands  ? ;-)

--
Fred
fole***@free.fr
Author
27 May 2010 8:14 PM
Family Tree Mike
"Family Tree Mike" wrote:

> 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).
>
> --
> Mike
> .
>

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

Mike
Author
26 May 2010 12:05 PM
Patrice
Hello,

> 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.

Have you tried to check the value for UBound(vInfo) or to look at Command ?

Rather than using a custom delimiter, my personal preference would be to use
http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs.aspx
that does this for you (AFAIK the separator is the blank and you can have
spaces inside an argument by enclosing it within ").

--
Patrice