Tech Off Thread

15 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Index was outside the bounds of the array.

Back to Forum: Tech Off
  • User profile image
    mancroft

    Consider the error:

    Index was outside the bounds of the array.

    in vb.net.

    Now I have three questions:

    1. What does it mean?

    2. What is causing it?

    3. If I get it (which I am) how can I force the program to continue running and not crash?

    I tried try:catch:finally but can't work out how to force the program to effectively ignore the error.

  • User profile image
    TomasDeml

    Not a good idea to IGNORE this exception...check your array index.

  • User profile image
    PeterF

    simply test the length of the array.
    if your array contains {3,12,18}
    and you want to access an item, check if the index is smaller than 3.

    Maybe you came from a traditional VB background. Arrays in VB.NET start with index zero.

    so in prseudocode:

    array[0] = 3
    array[1] = 12
    array[2] = 18

    array.length = 3
    if index < array.length
    return array[index]

    good luck
    Peter

  • User profile image
    Sven Groot

    One weird thing about arrays in VB is that you don't specify the length but the upperbound when declaring them. So "Dim myArray(5) As Integer" creates an array of length 6, with indices from 0 to 5 inclusive.

  • User profile image
    mancroft

    Thanks, guys!

  • User profile image
    W3bbo

    Sven Groot wrote:
    One weird thing about arrays in VB is that you don't specify the length but the upperbound when declaring them. So "Dim myArray(5) As Integer" creates an array of length 6, with indices from 0 to 5 inclusive.


    I don't call that "weird", it makes perfect sense to me.

    Of course, what's the official C/C++ style?

  • User profile image
    DoomBringer

    W3bbo wrote:
    Sven Groot wrote: One weird thing about arrays in VB is that you don't specify the length but the upperbound when declaring them. So "Dim myArray(5) As Integer" creates an array of length 6, with indices from 0 to 5 inclusive.


    I don't call that "weird", it makes perfect sense to me.

    Of course, what's the official C/C++ style?

    C/C++ makes more sense.  int[5] myArr makes an array of length 5, indices from 0 to 4.
    Of course, you won't get indices out of bounds using the foreach loop.  I'm so happy it exists.

  • User profile image
    Richard.Hein

    gwarburton wrote:


    I have a foreach loop iterating through a 2-dimensional array.  When I locally declare the array variable the loop operates correctly, however, when it is publicly declared it crashes with the "IndexOutOfRangeException" error.


    This could be caused because you are using multiple threads or something along those lines.  Remember also when you declare your array, it's not enough to just declare the size, you have to instantiate the members of the array. 

    A code sample would be helpful. 

    Did you declare your array like this [,] or this [][]?

  • User profile image
    gwarburton

    I'm working on something right now in VB.NET and I am hoping that you could help me.

    Your comment:

    "Of course, you won't get indices out of bounds using the foreach loop.  I'm so happy it exists."

    Almost precisely describes my problem.

    I have a foreach loop iterating through a 2-dimensional array.  When I locally declare the array variable the loop operates correctly, however, when it is publicly declared it crashes with the "IndexOutOfRangeException" error.

    Is there a known problem with arrays and foreach loops in VB.NET that you're referring to in your comment?  And if so, could you discuss it?

    Thanks!  btw, hello from "The Future!"

    I figured it out.  The array was being declared with only 1 index.

    [code]
    Public x as integer
    Public array(x, 5) as string

    Public Sub countNodes()

    x = XmlNodeList.count
    y = 0

    dim a, b, c, d, e, f as string

    For Each XmlNode in XmlNodeList
    a = array(y, 0)
    b = array(y, 1)
    c = array(y, 2)
    d = array(y, 3)
    e = array(y, 4)
    f = array(y, 5)
    y=y+1
    loop
    end sub
    [/code]

    This is incase anyone else comes across my issue.

  • User profile image
    gwarburton

    I just edited my post to include example code.

    I was attempting to publicly declare the array in order to use an array.foreach(of T)() action.

    I side-stepped that by using a Do Until Loop.

    Thanks for Responding!

    I've got two follow up questions if you're willing:

    Multi-Threading:

    I'm writing a COM visialbe DLL that will be activated by a MSMQ trigger.  Meaning that it is possible that it will be triggered while it is still running.  My questions are these:

    Will the currently running DLL create a new instance of itself and execute?  I need to make sure that it won't.

    Array()():

    What is ()()?

    Thanks!

  • User profile image
    ChloeJacobs

    gwarburton said:
    I just edited my post to include example code.

    I was attempting to publicly declare the array in order to use an array.foreach(of T)() action.

    I side-stepped that by using a Do Until Loop.

    Thanks for Responding!

    I've got two follow up questions if you're willing:

    Multi-Threading:

    I'm writing a COM visialbe DLL that will be activated by a MSMQ trigger.  Meaning that it is possible that it will be triggered while it is still running.  My questions are these:

    Will the currently running DLL create a new instance of itself and execute?  I need to make sure that it won't.

    Array()():

    What is ()()?

    Thanks!
    Hi,

    I am receiving an 'Index was outside the bounds of the array.' error.

    Can someone please look into my code below and advise why i am receiving this error? Code below:

    ----------------------------------------------------------------------------------------------------------------------------------------

    Case "TJ"

    Try

    Dim xmlRoot As Xml.XmlNode

    xmlDoc.LoadXml(RichTextBox1.Text)

    xmlRoot = xmlDoc.DocumentElement

    Dim LOADTYPE As String = xmlRoot.SelectSingleNode("ADVERT/ROOT").Attributes("LOADTYPE").Value

    Dim LIVEDAYS As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("LIVEDAYS").Value)

    Dim RATEUNIT As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("RATEUNIT").Value

    Dim SALARYMIN As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("SALARYMIN").Value)

    Dim SALARYMAX As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("SALARYMAX").Value)

    Dim INDUSTRYLONGNAME As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("INDUSTRYLONGNAME").Value

    Dim INDUSTRY As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/ADDITIONALJOBTYPE").Attributes("INDUSTRY").Value

    Dim GROUP As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/ADDITIONALJOBTYPE").Attributes("GROUP").Value

    Dim lines() As String = IO.File.ReadAllLines("validTJ.txt")

    For x As Integer = 0 To lines.GetUpperBound(0) Step 9

    If lines(x).Contains(LOADTYPE) And lines(x + 1).Contains(LIVEDAYS) And lines(x + 2).Contains(RATEUNIT) And lines(x + 3).Contains(SALARYMIN) And lines(x + 4).Contains(SALARYMAX) And lines(x + 5).Contains(SALARYMAX) And lines(x + 6).Contains(INDUSTRYLONGNAME) And lines(x + 7).Contains(INDUSTRY) And lines(x +Eye Rolling.Contains(GROUP) Then

    TextBox2.Text = "The XML is Formatted Correctly."

    Exit Sub

    Else

    Dim m As New TJMatches

    m.numberOfMatches = 0

    m.LOADTYPEMatches = lines(x).Contains(LOADTYPE)

    If m.LOADTYPEMatches Then m.numberOfMatches += 1

    m.LIVEDAYSMatches = lines(x + 1).Contains(LIVEDAYS)

    If m.LIVEDAYSMatches Then m.numberOfMatches += 1

    m.RATEUNITMatches = lines(x + 2).Contains(RATEUNIT)

    If m.RATEUNITMatches Then m.numberOfMatches += 1

    m.SALARYMINMatches = lines(x + 3).Contains(SALARYMIN)

    If m.SALARYMINMatches Then m.numberOfMatches += 1

    m.SALARYMAXMatches = lines(x + 4).Contains(SALARYMAX)

    If m.SALARYMAXMatches Then m.numberOfMatches += 1

    m.INDUSTRYLONGNAMEMatches = lines(x + 5).Contains(INDUSTRYLONGNAME)

    If m.INDUSTRYLONGNAMEMatches Then m.numberOfMatches += 1

    m.INDUSTRYMatches = lines(x + 5).Contains(INDUSTRY)

    If m.INDUSTRYMatches Then m.numberOfMatches += 1

    m.GROUPMatches = lines(x + 5).Contains(GROUP)

    If m.GROUPMatches Then m.numberOfMatches += 1

    listTJMatches.Add(m)

    End If

    Next

    listTJMatches.Sort(New TJComparer)

    Dim msg As String = String.Empty

    If Not listTJMatches(listTJMatches.Count - 1).LOADTYPEMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(LOADTYPE)

    RichTextBox1.SelectionLength = LOADTYPE.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "LOADTYPE matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).LIVEDAYSMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(LIVEDAYS)

    RichTextBox1.SelectionLength = LIVEDAYS.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "LIVEDAYS matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).RATEUNITMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(RATEUNIT)

    RichTextBox1.SelectionLength = RATEUNIT.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "RATEUNIT matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).SALARYMINMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(SALARYMIN)

    RichTextBox1.SelectionLength = SALARYMIN.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "SALARYMIN of doors matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).SALARYMAXMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(SALARYMAX)

    RichTextBox1.SelectionLength = SALARYMAX.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "SALARYMAX of owners matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).INDUSTRYLONGNAMEMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(INDUSTRYLONGNAME)

    RichTextBox1.SelectionLength = INDUSTRYLONGNAME.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "INDUSTRYLONGNAME matches = false"

    End If

    If Not listTJMatches(listTJMatches.Count - 1).INDUSTRYMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(INDUSTRY)

    RichTextBox1.SelectionLength = INDUSTRY.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "INDUSTRY matches = false"

    End If

    If Not listTJMatches(listTJMatches.Count - 1).GROUPMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(GROUP)

    RichTextBox1.SelectionLength = GROUP.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "GROUP matches = false"

    End If

    TextBox2.Text = msg

    Catch ex As Exception

    TextBox2.Text = (ex.Message)

    End Try
    ------------------------------------------------------------------------------------------------------------------------------------------


    The validTJ file is as below:

    LOADTYPE: A, D, U, a, d, u
    LIVEDAYS: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
    RATEUNIT: A, D, H
    SALARYMIN: 20000,25000
    SALARYMAX: 24999, 29999
    INDUSTRYLONGNAME: Accountancy, accountancy, Aerospace, aerospace, Sales, sales
    INDUSTRY: Accountancy, accountancy, Aerospace, aerospace, Sales, sales
    GROUP: Permanent, permanent, Contract, contract, Temporary, temporary, Part Time, part time


    Thank you every1!
    Chloe ~X~

  • User profile image
    jh71283

    ChloeJacobs said:
    gwarburton said:
    *snip*
    Hi,

    I am receiving an 'Index was outside the bounds of the array.' error.

    Can someone please look into my code below and advise why i am receiving this error? Code below:

    ----------------------------------------------------------------------------------------------------------------------------------------

    Case "TJ"

    Try

    Dim xmlRoot As Xml.XmlNode

    xmlDoc.LoadXml(RichTextBox1.Text)

    xmlRoot = xmlDoc.DocumentElement

    Dim LOADTYPE As String = xmlRoot.SelectSingleNode("ADVERT/ROOT").Attributes("LOADTYPE").Value

    Dim LIVEDAYS As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("LIVEDAYS").Value)

    Dim RATEUNIT As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("RATEUNIT").Value

    Dim SALARYMIN As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("SALARYMIN").Value)

    Dim SALARYMAX As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("SALARYMAX").Value)

    Dim INDUSTRYLONGNAME As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("INDUSTRYLONGNAME").Value

    Dim INDUSTRY As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/ADDITIONALJOBTYPE").Attributes("INDUSTRY").Value

    Dim GROUP As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/ADDITIONALJOBTYPE").Attributes("GROUP").Value

    Dim lines() As String = IO.File.ReadAllLines("validTJ.txt")

    For x As Integer = 0 To lines.GetUpperBound(0) Step 9

    If lines(x).Contains(LOADTYPE) And lines(x + 1).Contains(LIVEDAYS) And lines(x + 2).Contains(RATEUNIT) And lines(x + 3).Contains(SALARYMIN) And lines(x + 4).Contains(SALARYMAX) And lines(x + 5).Contains(SALARYMAX) And lines(x + 6).Contains(INDUSTRYLONGNAME) And lines(x + 7).Contains(INDUSTRY) And lines(x +Eye Rolling.Contains(GROUP) Then

    TextBox2.Text = "The XML is Formatted Correctly."

    Exit Sub

    Else

    Dim m As New TJMatches

    m.numberOfMatches = 0

    m.LOADTYPEMatches = lines(x).Contains(LOADTYPE)

    If m.LOADTYPEMatches Then m.numberOfMatches += 1

    m.LIVEDAYSMatches = lines(x + 1).Contains(LIVEDAYS)

    If m.LIVEDAYSMatches Then m.numberOfMatches += 1

    m.RATEUNITMatches = lines(x + 2).Contains(RATEUNIT)

    If m.RATEUNITMatches Then m.numberOfMatches += 1

    m.SALARYMINMatches = lines(x + 3).Contains(SALARYMIN)

    If m.SALARYMINMatches Then m.numberOfMatches += 1

    m.SALARYMAXMatches = lines(x + 4).Contains(SALARYMAX)

    If m.SALARYMAXMatches Then m.numberOfMatches += 1

    m.INDUSTRYLONGNAMEMatches = lines(x + 5).Contains(INDUSTRYLONGNAME)

    If m.INDUSTRYLONGNAMEMatches Then m.numberOfMatches += 1

    m.INDUSTRYMatches = lines(x + 5).Contains(INDUSTRY)

    If m.INDUSTRYMatches Then m.numberOfMatches += 1

    m.GROUPMatches = lines(x + 5).Contains(GROUP)

    If m.GROUPMatches Then m.numberOfMatches += 1

    listTJMatches.Add(m)

    End If

    Next

    listTJMatches.Sort(New TJComparer)

    Dim msg As String = String.Empty

    If Not listTJMatches(listTJMatches.Count - 1).LOADTYPEMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(LOADTYPE)

    RichTextBox1.SelectionLength = LOADTYPE.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "LOADTYPE matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).LIVEDAYSMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(LIVEDAYS)

    RichTextBox1.SelectionLength = LIVEDAYS.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "LIVEDAYS matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).RATEUNITMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(RATEUNIT)

    RichTextBox1.SelectionLength = RATEUNIT.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "RATEUNIT matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).SALARYMINMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(SALARYMIN)

    RichTextBox1.SelectionLength = SALARYMIN.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "SALARYMIN of doors matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).SALARYMAXMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(SALARYMAX)

    RichTextBox1.SelectionLength = SALARYMAX.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "SALARYMAX of owners matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).INDUSTRYLONGNAMEMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(INDUSTRYLONGNAME)

    RichTextBox1.SelectionLength = INDUSTRYLONGNAME.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "INDUSTRYLONGNAME matches = false"

    End If

    If Not listTJMatches(listTJMatches.Count - 1).INDUSTRYMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(INDUSTRY)

    RichTextBox1.SelectionLength = INDUSTRY.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "INDUSTRY matches = false"

    End If

    If Not listTJMatches(listTJMatches.Count - 1).GROUPMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(GROUP)

    RichTextBox1.SelectionLength = GROUP.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "GROUP matches = false"

    End If

    TextBox2.Text = msg

    Catch ex As Exception

    TextBox2.Text = (ex.Message)

    End Try
    ------------------------------------------------------------------------------------------------------------------------------------------


    The validTJ file is as below:

    LOADTYPE: A, D, U, a, d, u
    LIVEDAYS: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
    RATEUNIT: A, D, H
    SALARYMIN: 20000,25000
    SALARYMAX: 24999, 29999
    INDUSTRYLONGNAME: Accountancy, accountancy, Aerospace, aerospace, Sales, sales
    INDUSTRY: Accountancy, accountancy, Aerospace, aerospace, Sales, sales
    GROUP: Permanent, permanent, Contract, contract, Temporary, temporary, Part Time, part time


    Thank you every1!
    Chloe ~X~

    After

     For x As Integer = 0 To lines.GetUpperBound(0) Step 9

    I think it's worth checking that x is not greater than the length of your array -1.


    I also think that if you bold the line that throws the error, we have a better chance of helping you.

  • User profile image
    jh71283

    ChloeJacobs said:
    gwarburton said:
    *snip*
    Hi,

    I am receiving an 'Index was outside the bounds of the array.' error.

    Can someone please look into my code below and advise why i am receiving this error? Code below:

    ----------------------------------------------------------------------------------------------------------------------------------------

    Case "TJ"

    Try

    Dim xmlRoot As Xml.XmlNode

    xmlDoc.LoadXml(RichTextBox1.Text)

    xmlRoot = xmlDoc.DocumentElement

    Dim LOADTYPE As String = xmlRoot.SelectSingleNode("ADVERT/ROOT").Attributes("LOADTYPE").Value

    Dim LIVEDAYS As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("LIVEDAYS").Value)

    Dim RATEUNIT As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("RATEUNIT").Value

    Dim SALARYMIN As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("SALARYMIN").Value)

    Dim SALARYMAX As Integer = CInt(xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("SALARYMAX").Value)

    Dim INDUSTRYLONGNAME As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/JOB").Attributes("INDUSTRYLONGNAME").Value

    Dim INDUSTRY As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/ADDITIONALJOBTYPE").Attributes("INDUSTRY").Value

    Dim GROUP As String = xmlRoot.SelectSingleNode("ADVERT/ROOT/ADDITIONALJOBTYPE").Attributes("GROUP").Value

    Dim lines() As String = IO.File.ReadAllLines("validTJ.txt")

    For x As Integer = 0 To lines.GetUpperBound(0) Step 9

    If lines(x).Contains(LOADTYPE) And lines(x + 1).Contains(LIVEDAYS) And lines(x + 2).Contains(RATEUNIT) And lines(x + 3).Contains(SALARYMIN) And lines(x + 4).Contains(SALARYMAX) And lines(x + 5).Contains(SALARYMAX) And lines(x + 6).Contains(INDUSTRYLONGNAME) And lines(x + 7).Contains(INDUSTRY) And lines(x +Eye Rolling.Contains(GROUP) Then

    TextBox2.Text = "The XML is Formatted Correctly."

    Exit Sub

    Else

    Dim m As New TJMatches

    m.numberOfMatches = 0

    m.LOADTYPEMatches = lines(x).Contains(LOADTYPE)

    If m.LOADTYPEMatches Then m.numberOfMatches += 1

    m.LIVEDAYSMatches = lines(x + 1).Contains(LIVEDAYS)

    If m.LIVEDAYSMatches Then m.numberOfMatches += 1

    m.RATEUNITMatches = lines(x + 2).Contains(RATEUNIT)

    If m.RATEUNITMatches Then m.numberOfMatches += 1

    m.SALARYMINMatches = lines(x + 3).Contains(SALARYMIN)

    If m.SALARYMINMatches Then m.numberOfMatches += 1

    m.SALARYMAXMatches = lines(x + 4).Contains(SALARYMAX)

    If m.SALARYMAXMatches Then m.numberOfMatches += 1

    m.INDUSTRYLONGNAMEMatches = lines(x + 5).Contains(INDUSTRYLONGNAME)

    If m.INDUSTRYLONGNAMEMatches Then m.numberOfMatches += 1

    m.INDUSTRYMatches = lines(x + 5).Contains(INDUSTRY)

    If m.INDUSTRYMatches Then m.numberOfMatches += 1

    m.GROUPMatches = lines(x + 5).Contains(GROUP)

    If m.GROUPMatches Then m.numberOfMatches += 1

    listTJMatches.Add(m)

    End If

    Next

    listTJMatches.Sort(New TJComparer)

    Dim msg As String = String.Empty

    If Not listTJMatches(listTJMatches.Count - 1).LOADTYPEMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(LOADTYPE)

    RichTextBox1.SelectionLength = LOADTYPE.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "LOADTYPE matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).LIVEDAYSMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(LIVEDAYS)

    RichTextBox1.SelectionLength = LIVEDAYS.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "LIVEDAYS matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).RATEUNITMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(RATEUNIT)

    RichTextBox1.SelectionLength = RATEUNIT.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "RATEUNIT matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).SALARYMINMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(SALARYMIN)

    RichTextBox1.SelectionLength = SALARYMIN.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "SALARYMIN of doors matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).SALARYMAXMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(SALARYMAX)

    RichTextBox1.SelectionLength = SALARYMAX.ToString.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "SALARYMAX of owners matches = false" & Environment.NewLine

    End If

    If Not listTJMatches(listTJMatches.Count - 1).INDUSTRYLONGNAMEMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(INDUSTRYLONGNAME)

    RichTextBox1.SelectionLength = INDUSTRYLONGNAME.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "INDUSTRYLONGNAME matches = false"

    End If

    If Not listTJMatches(listTJMatches.Count - 1).INDUSTRYMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(INDUSTRY)

    RichTextBox1.SelectionLength = INDUSTRY.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "INDUSTRY matches = false"

    End If

    If Not listTJMatches(listTJMatches.Count - 1).GROUPMatches Then

    RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(GROUP)

    RichTextBox1.SelectionLength = GROUP.Length

    RichTextBox1.SelectionColor = Color.Red

    msg &= "GROUP matches = false"

    End If

    TextBox2.Text = msg

    Catch ex As Exception

    TextBox2.Text = (ex.Message)

    End Try
    ------------------------------------------------------------------------------------------------------------------------------------------


    The validTJ file is as below:

    LOADTYPE: A, D, U, a, d, u
    LIVEDAYS: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
    RATEUNIT: A, D, H
    SALARYMIN: 20000,25000
    SALARYMAX: 24999, 29999
    INDUSTRYLONGNAME: Accountancy, accountancy, Aerospace, aerospace, Sales, sales
    INDUSTRY: Accountancy, accountancy, Aerospace, aerospace, Sales, sales
    GROUP: Permanent, permanent, Contract, contract, Temporary, temporary, Part Time, part time


    Thank you every1!
    Chloe ~X~

    In fact I notice that you're also doing lines(x+7) and so on.... seems dangerous.


    What is the overall purpose of the function? We may be able to suggest some other ways of doing it.

  • User profile image
    ccatto

    Hey Now Mancroft,

     

    Index was outside the bounds of the array.

     

    1. What does it mean?
         Array & Data Set values may not be the same
    2. What is causing it?
         IndexOutOfRangeException
          Stack Trace:
          [IndexOutOfRangeException: Index was outside the bounds of the array.]
    3. If I get it (which I am) how can I force the program to continue running and not crash?
         correct the data
         dr["Item_Four"] = xrow.ItemArray[4];

     

    Thx 4 the info on the other comments people


    Catto

  • User profile image
    Ion Todirel

    ccatto said:

    Hey Now Mancroft,

     

    Index was outside the bounds of the array.

     

    1. What does it mean?
         Array & Data Set values may not be the same
    2. What is causing it?
         IndexOutOfRangeException
          Stack Trace:
          [IndexOutOfRangeException: Index was outside the bounds of the array.]
    3. If I get it (which I am) how can I force the program to continue running and not crash?
         correct the data
         dr["Item_Four"] = xrow.ItemArray[4];

     

    Thx 4 the info on the other comments people


    Catto

    thanks, now he can get right away and fix his "code" Smiley

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.