Guest Danno Posted October 17, 2002 Posted October 17, 2002 I am trying to add some numbers to an array and I am getting an error. Here is the code: Dim rate(17) As ArrayList Dim count As Short Dim startRate As Single = 6.0 For count = 0 To 16 rate(count).Add(startRate) startRate += 0.00125 lstDisplay.Items.Add(rate(count)) Next And the error I get is: "An unhandled exception of type 'System.NullReferenceException' occurred in LoanAnalyzer.exe Additional information: Object reference not set to an instance of an object." What am I missing? Quote
*Gurus* divil Posted October 17, 2002 *Gurus* Posted October 17, 2002 You're missing knowledge of the difference between an array and an ArrayList. I can't really tell what you're trying to accomplish with this piece of code, but you probably want either of these: Dim rate(17) As Double or Dim rate As ArrayList = New ArrayList() 'Then rate.Add(etc etc) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Derek Stone Posted October 17, 2002 *Gurus* Posted October 17, 2002 An ArrayList is a type of collection, just in case you're wondering. You can't loop through it's elements that simply. You need to create an IEnumerable object if you want to enumerate through its elements. Quote Posting Guidelines
Guest Danno Posted October 17, 2002 Posted October 17, 2002 I am trying to display an interest rate starting at 6% through 8% in a ListBox in .125% increments. I wanted to put them into an array and then display them. With "Dim rate(17) As Double" is rate an array filled with values that are doubles? I don't have to explicitly declare it as an array? I will look into IEnumerable object (haven't used it yet) Quote
*Gurus* Derek Stone Posted October 17, 2002 *Gurus* Posted October 17, 2002 With "Dim rate(17) As Double" is rate an array filled with values that are doubles?Yes I don't have to explicitly declare it as an array?No, you don't. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.