Jump to content
Xtreme .Net Talk

Fill an array (or arrayList?)


Recommended Posts

Posted

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?

  • *Gurus*
Posted

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)

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...