How to get te last value of a multidimensional array?

i.

I have a Multidimensional array.
that have the data of a listbox.

So If I want to get the value of the first row and the eight column, I do this: my2dArray(0,8)

But how can I walk through that array and get the last value of the eight column?

Thanks

That’s actually the 9th column :slight_smile:

Anyways, use Ubound with the optional parameter specifying which dimension you want the upper bound of

dim sizeX As integer = Ubound(my2dArray, 1) dim sizeY As integer = Ubound(my2DArray, 2)

note, this form of Ubound doesn’t work.
dim sizeX As integer = my2DArray.Ubound(1)

[quote=211473:@Will Shank]That’s actually the 9th column :slight_smile:

Anyways, use Ubound with the optional parameter specifying which dimension you want the upper bound of

dim sizeX As integer = Ubound(my2dArray, 1) dim sizeY As integer = Ubound(my2DArray, 2)

note, this form of Ubound doesn’t work.
dim sizeX As integer = my2DArray.Ubound(1)[/quote]
Of course, the 9th column. Arrays are zero based.

Thanks.

So If I want to get the last value of the 9th column I need to do this:

dim sizeY As integer = Ubound(my2DArray, 1)
Msgbox my2dArray(sizeY,8)

Dim sum As Integer
Now If I want to sum all the values of that column I need to do a loop right?
Sum = sum+SizeY

For i As Integer = 0 to SizeY

Next

Pls correct me If I’m wrong

Thanks a lot

[quote=211475:@Gerardo García]Thanks.

So If I want to get the last value of the 9th column I need to do this:

dim sizeY As integer = Ubound(my2DArray, 1)
Msgbox my2dArray(sizeY,8)

Dim sum As Integer
Now If I want to sum all the values of that column I need to do a loop right?
Sum = sum+SizeY

For i As Integer = 0 to SizeY

Next

Pls correct me If I’m wrong

Thanks a lot[/quote]
I forgot this: Sum = sum + Val(my2dArray(sizeY,8)) NOT SUM = SUM+SIZEY.

But what about if The values of that column are currency or double?

[quote=211478:@Gerardo García]I forgot this: Sum = sum + Val(my2dArray(sizeY,8)) NOT SUM = SUM+SIZEY.

But what about if The values of that column are currency or double?[/quote]
JUST Kidding ! Only change integer to double to get the decimals :stuck_out_tongue: :stuck_out_tongue:

What Am I doing wrong?

I’m watching that the result is bigger, I export the data of the listbox to an excel spreadsheet.

Thats the code what I’m using:
Dim subtotal As DOUBLE
Dim SubtotalLbl As String
dim sizeY As integer = Ubound(my2DArray, 1)

For yap As integer = 0 to sizeY
Subtotal = subtotal + Cdbl(my2dArray(sizeY,9))

Next

SubtotalLbl = Str(FORMAT(subtotal,"\$###,###,###0.00"))
TotalImplbl = str(FORMAT(totalImpuestos,"\$###,###,###0.00"))
GranTotalbl = Str(FORMAT(GranTotal,"\$###,###,###0.00"))

And also I noticed that sometimes I get “0” in the sum.

[quote=211512:@Gerardo García]What Am I doing wrong?

I’m watching that the result is bigger, I export the data of the listbox to an excel spreadsheet.

Thats the code what I’m using:
Dim subtotal As DOUBLE
Dim SubtotalLbl As String
dim sizeY As integer = Ubound(my2DArray, 1)

For yap As integer = 0 to sizeY
Subtotal = subtotal + Cdbl(my2dArray(sizeY,9))

Next

SubtotalLbl = Str(FORMAT(subtotal,"\$###,###,###0.00"))
TotalImplbl = str(FORMAT(totalImpuestos,"\$###,###,###0.00"))
GranTotalbl = Str(FORMAT(GranTotal,"\$###,###,###0.00"))

And also I noticed that sometimes I get “0” in the sum.[/quote]
I noticed my error. I’m not using next. I was summing the last value of the array as many rows has the array.

The right code is this: Subtotal = subtotal + Val(my2dArray(yap,9))
NOT THAT: Subtotal = subtotal + Val(my2dArray(sizeY,9))