473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Array's

Hello

I messaged before about arrays and got help and example off Cor. Here it is

Dim myArray As New ArrayLis
myArray.Add("Peugeot"
myArray.Add("Ferari"
myArray.Add("Fiat"
myArray.Add("Renault"
myArray.RemoveAt(0
myArray.Insert(1, "Mercedes"
myArray.Clear(

I want to ask how i can loop through an arraylist so i can get these values into another control
I tried this but it gets error

Private CarArray as new ArrayLis
Private Index as intege

Button1_Onclick................................... ...............
CarArray.add(Index, Textbox1.Text
Index = Index +

why can i not do this coding
thank yo
Jul 21 '05 #1
13 1287
What do you want to do ?

The ArrayList.Add - method has got only one signature which takes only one parameter as being the object to be added to the list.
Jul 21 '05 #2
Cor
Hi Varun,

Diner time here but a quick one.

You better can add it to a listbox, but to show you the loop to add the
array to a textbox, while I am in a hurry

\\\
dim i as integer
for i = 0 to myarray.length - 1
mytextbox.text = mytextbox.text & myarray(i).tostring & vbcrlf
next
///

I hope this helps,

If there is an error, I did it really very quick.

:-))

Cor
Jul 21 '05 #3
Hello,

what i want to do is loop through the arraylist so that i can add all the values contained in this array into a datatable.

I used a simple array before with the following code to loop through my array and add values to a datatable:

For Index = 0 To (Index - 1)
CarDTRow = ds.Tables("CarDT").NewRow()
CarDTRow ("CarReg") = txtCarReg.Text
CarDTRow ("CarMake") = CarArray(Index)
ds.Tables("CarDT").Rows.Add(CarDTRow)
Next Index

I wanted to empty my array when the values were added to the datatable but i was told that i couldnt and that i would need to use a arraylist!!

Now that i have to use the arraylist, i am no longer sure on how to loop through my array the way i did when i use just the normal Array (not arrayList). Can u help me with this? Is this possible?
Jul 21 '05 #4
,
Thx Cor
Jul 21 '05 #5
Thx Cor

I have tried this but i get error that sayin
'length' is not a member of 'System.Collections.ArrayList

i did this
Dim CarArray as new Arraylis
Dim i As Intege
For i = 0 To CarArrayList.length -
' ...................
Nex

the 3rd line of the coding above is highlited as problem code. (CarArrayList.length - 1 is highlighted)

Can anyone advise me
Thank you.
Jul 21 '05 #6
Don't you have IntelliSense

Use ".Count" instead of ".Length".
Jul 21 '05 #7
Hi,

i try using .count but i get an error that says:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
I have coded this:
Dim max As Integer = CarArray.Count - 1
Dim i As Integer
For i = 0 To max
CarDTRow = ds.Tables("CarDT").NewRow()
CarDTRow ("CarReg") = txtCarReg.Text
CarDTRow ("CarMake") = CarArray(Index)
CarDTRow("NoOfCarSales") = NoOfCarSalesArray
ds.Tables("CarDT").Rows.Add(CarDTRow)
Next Index

The code breaks on this line:
CarDTRow("NoOfCarSales") = NoOfCarSalesArray

The first array seems to work ok.
Very confused!!?

Jul 21 '05 #8
Hi,

i try using .count but i get an error that says:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
I have coded this:
Dim max As Integer = MyMealTypeArray.Count - 1
Dim i As Integer
For i = 0 To max
CarDTRow = ds.Tables("CarDT").NewRow()
CarDTRow ("CarReg") = txtCarReg.Text
CarDTRow ("CarMake") = CarArray(Index)
CarDTRow("NoOfCarSales") = NoOfCarSalesArray
ds.Tables("CarDT").Rows.Add(CarDTRow)
Next Index

The code breaks on this line:
CarDTRow("NoOfCarSales") = NoOfCarSalesArray

The first array seems to work ok.
Very confused!!?

Jul 21 '05 #9
Hi

i try using .count but i get an error that says

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dl
Additional information: Index was out of range. Must be non-negative and less than the size of the collection
I have coded this
Dim max As Integer = CarArray.Count -
Dim i As Intege
For i = 0 To ma
CarDTRow = ds.Tables("CarDT").NewRow(
CarDTRow ("CarReg") = txtCarReg.Tex
CarDTRow ("CarMake") = CarArray(i
CarDTRow("NoOfCarSales") = NoOfCarSalesArray(i
ds.Tables("CarDT").Rows.Add(CarDTRow
Next Inde

The code breaks on this line
CarDTRow("NoOfCarSales") = NoOfCarSalesArra

The first array seems to work ok.
Very confused!!


Jul 21 '05 #10
Cor
Hi Varun,

Sorry for that lenght answer, I do not know how it happens that I did that,
because mostly I try to be secure not to mix that up.

But luckely you got your answer from TC mc Queen.

The error is now I think in,
CarDTRow("NoOfCarSales") = NoOfCarSalesArray(i)


What is that array NoOfCarSalesArray.

When it is the same lenght of the other one it should go, but I doubt that.

Cor
Jul 21 '05 #11
Hello Cor,

I have 2 arrays.
Private CarArray As New ArrayList()
Private NoOfCarSalesArray As New ArrayList()
Private i As Intreger = 0

When i add the car name to the first array (CarArray), i also be add the quantity required in the NoOfCarSalesArray. They should then be on the same index number (i). They should always be the same length.

Here is my code for the button that adds these values to both the arraylists that i show u above.

CarArray.Add(txtCaraName.Text)
NoOfCarSalesArray.Add(txtCarQty.Text)
i = (i + 1)

I then try to get values out of both these arraylist and put them both into a row in my datatable.
Dim max As Integer = CarArray.Count - 1
Dim i As Integer
For i = 0 To max
CarDTRow = ds.Tables("CarDT").NewRow()
CarDTRow ("CarReg") = txtCarReg.Text
CarDTRow ("CarMake") = CarArray(i)
CarDTRow("NoOfCarSales") = NoOfCarSalesArray(i)
ds.Tables("CarDT").Rows.Add(CarDTRow)
Next Index

When i run this i get error:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

when i swap the line
Dim max As Integer = CarArray.Count - 1
to
Dim max As Integer = NoOfCarSalesArray.Count - 1

I do not get this error and the coding application runs but i still get problems. All the values above are added to the datatable but not the ones that get values from the arraylist!!!
I do not know why.
Should i be doing some more coding? i am not sure if i have missed things out?

Jul 21 '05 #12
Cor
Hi Varun,

Are you using VS.net or VB.net with an IDE?

If not add this instruction and look what is the result when you start.
(But look further I have also something else that is strange)

Before this line
messagebox.show(CarArray.count.tostring & "+" &
NoOfCarSalesArray.count.tostring)
Dim max As Integer = CarArray.Count - 1
Dim i As Integer
For i = 0 To max
CarDTRow = ds.Tables("CarDT").NewRow()
CarDTRow ("CarReg") = txtCarReg.Text
CarDTRow ("CarMake") = CarArray(i)
CarDTRow("NoOfCarSales") = NoOfCarSalesArray(i)
ds.Tables("CarDT").Rows.Add(CarDTRow)
Next Index

Make from this

Next

There is not integer Index in the loop it is i but that is automaticly taken
in this case.

Cor
Jul 21 '05 #13
Hello Cor,

That was a very clever of way performing a check. Thanku for that. I found that all values were added to the first array and non to the second.
I then change the addbutton_Onclick event to make it work properly. Thank you so much for your time and patience with me.
Im hoping now the problem is fix.

thank you
Jul 21 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.