2 Replies - 453 Views - Last Post: 27 November 2012 - 10:01 AM Rate Topic: -----

#1 DoN_UK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-November 11

Index was out of range. Must be non-negative and less than the size of

Posted 27 November 2012 - 06:04 AM

Hi, I have a string in a textbox which looks like
"81.213.224.141","81.213.224.141","UAE","United Emirates","D3","Dubai","WildWadi","","32.100000","3.200100","Telecom","Eutelsat - SanComm"
. I performed some splitting operations on that string just to get the data between the quotations, hyphens while avoiding commas. I store each parameter in a string and then I assign each string to show in a label. The first IP address I am able to get it to show in the label. However, the second or third or fourth parameter I am not able to show them In other labels. It shows me the index out of range error.

Code:

Dim a = """81.213.224.141"",""81.213.224.141"",""UAE"",""United Emirates"",""D3"",""Dubai"",""WildWadi"","",""32.100000"",""3.200100"",""Telecom"",""Eutelsat - SanComm"""

        Dim noQuotes = a.Replace("""", "") ' Update this line with Textbox1.Text
        Dim split = noQuotes.Split(",") ' Split on commas

        Dim result As New List(Of String)()

        For Each str_get As String In split
            Dim splitStr = str_get.Split("-") ' Perform secondary split on dash
            For Each str_split As String In splitStr
                result.Add(str_split.Trim()) ' Enter into result list
                Label1.Text = result(0) 
                Label2.Text = result(1)
            Next
        Next


Any suggestions ??

Is This A Good Question/Topic? 0
  • +

Replies To: Index was out of range. Must be non-negative and less than the size of

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Index was out of range. Must be non-negative and less than the size of

Posted 27 November 2012 - 06:37 AM

Suggestions? Many, but for starters, place a breakpoint at the first line, where you Dim a. Run the code. When it stops, single-step through the code, checking each variable that changes after stepping through it.

You will see that str_split does not always have a length of 2.

This post has been edited by lar3ry: 27 November 2012 - 06:38 AM

Was This Post Helpful? 1
  • +
  • -

#3 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 975
  • Joined: 09-May 09

Re: Index was out of range. Must be non-negative and less than the size of

Posted 27 November 2012 - 10:01 AM

Have a look at this

      'String
        Dim Values = """81.213.224.141"",""81.213.224.141"",""UAE"",""United Emirates"",""D3"",""Dubai"",""WildWadi"","",""32.100000"",""3.200100"",""Telecom"",""Eutelsat - SanComm"""

        'String with no quotes  
        Dim valuesWithoutQuotes = Values.Replace("""", "")

        'Array of strings 
        Dim result = valuesWithoutQuotes.Split(",")

        'Assign values to labels
        Label1.text = result(0).Trim
        Label2.Text = result(1).Trim



Hope this helps
Kevin

This post has been edited by deery5000: 27 November 2012 - 10:10 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1