4 Replies - 365 Views - Last Post: 01 May 2012 - 03:33 PM Rate Topic: -----

#1 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

An "OutOfRange Exception" only after publishing.

Posted 01 May 2012 - 03:03 PM

Hi,

I keep finding that a block of code I use to find file, list them in a listview, then get the first value of the item when clicked is causing an OutOfRange exception but only once the application has been published.

The JIT Debugger gives me this;

Quote

InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index.


The code trying to do the work;
    ' Single click on a log file should load that file
    Private Sub LogFileSelected() Handles ListView3.SelectedIndexChanged
        Dim fileName As String = ListView3.SelectedItems.Item(0).Text
        Dim filePath As String = LogFileDir + fileName

        ' Call ReadToChart to fill the chart with data from that file.
        ReadToChart(filePath)
    End Sub


If I click continue from the debugger, the code actions its task exactly as intended,
and I have not been able to replicate the issue from the designer so I can't tell why it does it.
It also only does it after a logfile has already been selected, so second selected item then every subsequent item thereafter.

This post has been edited by Saldash: 01 May 2012 - 03:04 PM


Is This A Good Question/Topic? 0
  • +

Replies To: An "OutOfRange Exception" only after publishing.

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: An "OutOfRange Exception" only after publishing.

Posted 01 May 2012 - 03:12 PM

SelectedIndexChanged hides a nasty feature/bug (I'm not sure what it is). When you change a selection in a listView, this event fires twice: once when it clear the selection, and second when it make the new one. In the first case, SelectedItems (I think) is assigned, but has no values. So, make a check if Count SelectedItems of SelectedItems is greater than 0. IF it is, proceed, else exit.

This post has been edited by Ionut: 01 May 2012 - 03:13 PM

Was This Post Helpful? 0
  • +
  • -

#3 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 72
  • View blog
  • Posts: 323
  • Joined: 12-January 11

Re: An "OutOfRange Exception" only after publishing.

Posted 01 May 2012 - 03:16 PM

How about this:

Dim fileName, filePath as String

If ListView3.SelectedItems.Count>0 Then
     fileName = ListView3.SelectedItems.Item(0).Text
     filePath = LogFileDir + fileName 
     'if you are concatonating text i would suggest using & instead of +
     ReadToChart(filePath)
End If



That should bypass the issue if there are no items in ListView3.SelectedItems.
Was This Post Helpful? 0
  • +
  • -

#4 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

Re: An "OutOfRange Exception" only after publishing.

Posted 01 May 2012 - 03:21 PM

Ionut, that's worked a treat..
I wonder why it hadn't popped up in the last few builds I've done - weird.

Oh well, that's sorted - Thank You!

EDIT: Psyguy, that's exactly the approach I've taken.
I've thrown in a few other "checking" bits and so far seems quite stable :)

This post has been edited by Saldash: 01 May 2012 - 03:23 PM

Was This Post Helpful? 0
  • +
  • -

#5 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: An "OutOfRange Exception" only after publishing.

Posted 01 May 2012 - 03:33 PM

Yeah had the same issues the other day whilst using a background worker and a datagrid it was really weird
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1