Fill an array (or arrayList?)

  • Thread starter Thread starter Danno
  • Start date Start date
D

Danno

Guest
I am trying to add some numbers to an array and I am getting an error. Here is the code:


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?
 
Youre missing knowledge of the difference between an array and an ArrayList. I cant really tell what youre trying to accomplish with this piece of code, but you probably want either of these:

Code:
Dim rate(17) As Double

or

Dim rate As ArrayList = New ArrayList() Then rate.Add(etc etc)
 
An ArrayList is a type of collection, just in case youre wondering. You cant loop through its elements that simply. You need to create an IEnumerable object if you want to enumerate through its elements.
 
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 dont have to explicitly declare it as an array?

I will look into IEnumerable object (havent used it yet)
 
Back
Top