ArrayLists

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi can anyone help me answer a few questions regarding arralists

1) If i add numerous intergers to an arraylist (i.e 4, 1 ,7, 23, 4, 2) how would i retrieve the INDEX of the value that is the smallest

2) When i set the datasource property of a datagrid to an arraylist containing the list of integers no values are shown in my datagrid. The correct number of rows seem to appear everytime but i just dont get the values showing!
When i changed the datasource to a different arraylist containg Dates, i do not get the dates displayed but instead i get a column that has the title 'length'. The value of this column is always 10. i presume this means the length of the date value (i.e 02/04/2004 = length of 10)!!! Once again the correct number of rows are shown but they contain the value 10 instead of the actual date!!!
Does anyone know what im doin wrong?
I add to the arraylist like
Dim Variable1 as Int32 = CInt(Textbox1.text
Arraylist.Add(Variable1

If anyone can help me on any of these answersit would be appreciated.
 
function GetIndexOfSmallestNumber(arraylist a) as int
int nSmallestValue = a.Item(0)
int nSmallestIndex = 0
for n = 1 to a.Count-1
if a.Item(n) < nSmallestValue then
nSmallestIndex = n
nSmallestValue = a.Item(n)
end if
next n
return nSmallestIndex


Hi I said:
Hi can anyone help me answer a few questions regarding arralists?

1) If i add numerous intergers to an arraylist (i.e 4, 1 ,7, 23, 4, 2) how
would i retrieve the INDEX of the value that is the smallest?
2) When i set the datasource property of a datagrid to an arraylist
containing the list of integers no values are shown in my datagrid. The
correct number of rows seem to appear everytime but i just dont get the
values showing!!
When i changed the datasource to a different arraylist containg Dates, i
do not get the dates displayed but instead i get a column that has the title
'length'. The value of this column is always 10. i presume this means the
length of the date value (i.e 02/04/2004 = length of 10)!!! Once again the
correct number of rows are shown but they contain the value 10 instead of
the actual date!!!
 
i Tried the code that u provided me but i have encountered a few problems. This is what i tried..

function GetIndexOfSmallestNumber(arraylist a) as int3
Dim nSmallestValue As Int3
Dim nSmallestIndex As Int3

CInt(nSmallestValue = a.Item(0)
nSmallestIndex =
For i = 1 To a.Count -
If a.Item(i) < nSmallestValue The
nSmallestIndex =
nSmallestValue = a.Item(i
End I
Next
Return nSmallestInde

The pronlem is that all the 'a' are underlined. When i hover over it i get the error message that states
'A' is not accessible in this content because it is 'Private'

How can i fix this problem
Also how would i call this function when i want to run this code?
As u guessed im new to the world of VB.NET
 
i Tried the code that u provided me but i have encountered a few problems. This is what i tried...

The pronlem is that all the 'a' are underlined. When i hover over it i get the error message that states:
'A' is not accessible in this content because it is 'Private'.

You're mixing C# and VB Syntax. Try this:

Public Function GetIndexOfSmallestNumber(a As ArrayList) As Int32
Dim nSmallestValue As Int32
Dim nSmallestIndex As Int32

nSmallestValue = CInt(a.Item(0))
nSmallestIndex = 0
For i = 1 To a.Count - 1
If a.Item(i) < nSmallestValue Then
nSmallestIndex = i
nSmallestValue = a.Item(i)
End If
Next
Return nSmallestIndex
End Function
Also how would i call this function when i want to run this code??
As u guessed im new to the world of VB.NET.

Call it with code similar to this:

Dim MyArrayList As New ArrayList

'Code to add items to the array list here

Dim iSmallestIndex As Int32 = GetIndexOfSmallestNumber(MyArrayList)
 
Back
Top