2 Replies - 19788 Views - Last Post: 21 November 2006 - 01:04 PM Rate Topic: -----

#1 hardley98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-October 06

read data from listbox

Posted 21 November 2006 - 06:38 AM

I have code that accepts input from key entry and displays in a listbox. When I try to read the data in the list box, I'm getting and An Unhandled exception of type 'SystemArgumentOutOfRangeException' occurred in system.window.forms.dll. Additional information: Specified argument was out of range of valid values.

The line of code highlighted is
Sum = Sum + DisplayListBox.Items(Count)

What does this error mean or how to read data from a listbox?


Private Sub ComputeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComputeButton.Click
		Dim Count, MaxCount As Byte
		Dim Sum As Double

		REM Set the number of items in the list
		MaxCount = DisplayListBox.Items(Count)

		Sum = 0

		REM Compute the sum

		For Count = 0 To MaxCount - 1
			Sum = Sum + DisplayListBox.Items(Count)
		Next

		REM Compute and display the average
		AverageLabel.Text = FormatNumber(Sum / MaxCount)

	End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: read data from listbox

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: read data from listbox

Posted 21 November 2006 - 09:39 AM

The problem is when you initially get the count of items in your listbox.
MaxCount = DisplayListBox.Items(Count)



Should be like this:
MaxCount = DisplayListBox.Items.Count()


Was This Post Helpful? 1

#3 hardley98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-October 06

Re: read data from listbox

Posted 21 November 2006 - 01:04 PM

Thanks jayman9
Appreciate the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1