Re: [2005] Array List Error
The problem is likely that you have declare My.Settings.CustomerID as an ArrayList, but haven't instantiated it anywhere, so there's no object to add the string to.
Before the .Add line, put in:
Code:
If My.Settings.CustomerID Is Nothing Then
My.Settings.CustomerID = new ArrayList() 'Or whatever you've declare it as.
End If
Re: [2005] Array List Error
- I have delcared My.Settings.CustomerID as an ArrayList.
I want to add more stuff to the arraylist then just one so i cant just do Is Nothing Then etc...
Do you mean i must declare My.Settings.CustomerID as a new ArrayList() then were do i do the code i declared it as.... ill try figure it out if not ill come back here.
Re: [2005] Array List Error
nvm i see i forgot how arrays work.
ArrayList(Then here i put how many items/strings are in here) is it possible to make it infinity so i can add any amount?
Re: [2005] Array List Error
Quote:
Originally Posted by noahssite
- I have delcared My.Settings.CustomerID as an ArrayList.
I want to add more stuff to the arraylist then just one so i cant just do Is Nothing Then etc...
Do you mean i must declare My.Settings.CustomerID as a new ArrayList() then were do i do the code i declared it as.... ill try figure it out if not ill come back here.
That's why there's the If there. The first time you access it, it's going to be Nothing, so it will get instantiated. The next time you access it, it will not be Nothing, so you'll skip the instantiation and just go onto the Add.
Re: [2005] Array List Error
Sorry im a bit confused it doesnt seem to work i may have done it wrong when inserting your code...
Can you give me a small example with the code i used.
Re: [2005] Array List Error
Code:
Try
My.Settings.CustomerNum = My.Settings.CustomerNum + 1
CustomerNum = My.Settings.CustomerNum
If My.Settings.CustomerID Is Nothing Then
My.Settings.CustomerID = new ArrayList() 'Or whatever you've declare it as.
End If
My.Settings.CustomerID.Add(" Name: " & txtName.Text.Trim & " Phone#: " & txtPhone.Text.Trim & " Country: " & txtCountry.Text.Trim & " State/Province: " & txtProvince.Text.Trim & " City: " & txtCity.Text.Trim & " Address: " & txtAddress.Text.Trim & " C#: " & (CustomerNum))
My.Settings.CustomerNum = CustomerNum
CustomerRecords.frmCustomerView.customerview.Items.Add(My.Settings.CustomerID(CustomerNum))
Catch ex As Exception
MsgBox("Sorry, Customer Tracker 1.0 has encounted a problem. " & ex.Message, MsgBoxStyle.Critical, "Error")
End Try
Re: [2005] Array List Error
Just an FYI, if you are using .NET 2.0, the DO NOT USE arraylists.
The ONLY time you should use an arraylist, is when you need to group objects of DIFFERENT types.
Otherwise use a generic class of the type your list holds. Generics were added in .NET 2.0, and all but killed the need to use generic arraylists that need constant type conversions.
Re: [2005] Array List Error
It says index was out of range... Same message i got on my own code.
That means i cant just right .....New ArrayList() i need to add something in between the ()? or what?
What do you mean by:
Quote:
My.Settings.CustomerID = new ArrayList() 'Or whatever you've declare it as.
I declared it as a ArrayList...
Re: [2005] Array List Error
Quote:
Originally Posted by noahssite
It says index was out of range... Same message i got on my own code.
That means i cant just right .....New ArrayList() i need to add something in between the ()? or what?
What line does the error come on? You don't need any parameters to declare an arraylist
Quote:
Originally Posted by noahssite
What do you mean by:
I declared it as a ArrayList...
As kleinma said, why are you using an ArrayList when you simply want to add a bunch of strings to it? A List(Of String) would be much more efficient.
Re: [2005] Array List Error
How does the List(Of String) work? Ill look into that then. I wanted an arraylist because im not good with databases so i wanted to replace a datebase with just many strings...
So i thought it would be reasonable to make an Array List.
Re: [2005] Array List Error
An ArrayList is a list of objects. If you want to use the data for anything, then it has to be cast into the appropriate type in order to be accessed. When you use a List, you can specify what's going to be in the List, so you don't have to do any conversions to save and retrieve it. It's faster and more efficient.
Re: [2005] Array List Error
not being good at something is no excuse to not use something. It presents the chance to learn about it and then be able to use it.
A list of strings and a database are 2 totally different animals. If you need any type of data structure at all, then storing a whole bunch of info in 1 string is a very bad idea.
There are lots of tutorials about databases and XML documents on this forum and around the web, and of course you can ask questions when you are stuck somewhere.
So I have no idea what your app does, but you should use the right tools for the job if you want to make the app any good.