How to get the values from array's dimensions

The quantity of the array's dimensions are also unknown.

Page 1 of 1

6 Replies - 7911 Views - Last Post: 30 January 2009 - 05:46 PM Rate Topic: -----

#1 fiaolle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-March 08

How to get the values from array's dimensions

Posted 29 January 2009 - 01:53 PM

:blink: Hi

I wounder if there is a way to get the values from array's dimensions, without knowing how many dimensions the array has.
I know how to do if I know the array's dimensions, but not a clue if I don't
know the array's dimensions.


Sub getArr(ByVal arr)
Dim s as String
Dim i, j As Integer

For i = 0 To arr.rank

For j = 0 To arr.getupperbound(1)

s = s + arr(i, j) + " "

Next
s = s + vbCrLf
End If

Next

End Sub

I hope someone can give me a clue.

Fia

Is This A Good Question/Topic? 0
  • +

Replies To: How to get the values from array's dimensions

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: How to get the values from array's dimensions

Posted 29 January 2009 - 03:54 PM

Please use the code tags when posting your code examples:

:code:

Shouldn't For j = 0 To arr.getupperbound(1) be For j = 0 To arr.getupperbound(i)?

Quote

Array.Rank Property

Gets the rank (number of dimensions) of the Array.

This post has been edited by n8wxs: 29 January 2009 - 03:55 PM

Was This Post Helpful? 0
  • +
  • -

#3 fiaolle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-March 08

Re: How to get the values from array's dimensions

Posted 30 January 2009 - 02:04 AM

Hi
Yes it should be an i in the getupperbound method,Sorry. But knowing just the number of dimensions doesn't help me to retrieve all the elements from the array. I don't know how many for loops I have to do, to iterate through the dimensions. Isn't there a collection of the dimensions so I can use a for each loop or something, to retrieve all the values for that dimension?

Please help
Fia
Was This Post Helpful? 0
  • +
  • -

#4 buckrogers1965  Icon User is offline

  • New Member

Reputation: 9
  • View blog
  • Posts: 87
  • Joined: 23-January 09

Re: How to get the values from array's dimensions

Posted 30 January 2009 - 03:18 AM

Oops, posting in the wrong place.

This post has been edited by buckrogers1965: 30 January 2009 - 03:20 AM

Was This Post Helpful? 0
  • +
  • -

#5 chrixko  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 63
  • Joined: 25-November 08

Re: How to get the values from array's dimensions

Posted 30 January 2009 - 03:40 AM

Dont know exactly but maybe :

For example if its an StringArray:
For each StringPart as String in StringArray
  Stringpart.('what do you want to to with it)
next


Was This Post Helpful? 0
  • +
  • -

#6 nightscream  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 237
  • Joined: 04-December 08

Re: How to get the values from array's dimensions

Posted 30 January 2009 - 03:09 PM

View Postchrixko, on 30 Jan, 2009 - 02:40 AM, said:

Dont know exactly but maybe :

For example if its an StringArray:
For each StringPart as String in StringArray
  Stringpart.('what do you want to to with it)
next


this should work for a normal array, don't really know for a multi array.
If that doesn't work why not use the method UBound, it will give you the size of the array
Was This Post Helpful? 0
  • +
  • -

#7 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: How to get the values from array's dimensions

Posted 30 January 2009 - 05:46 PM

View Postfiaolle, on 30 Jan, 2009 - 01:04 AM, said:

Hi
Yes it should be an i in the getupperbound method,Sorry. But knowing just the number of dimensions doesn't help me to retrieve all the elements from the array. I don't know how many for loops I have to do, to iterate through the dimensions. Isn't there a collection of the dimensions so I can use a for each loop or something, to retrieve all the values for that dimension?

Please help
Fia

See Array.GetEnumerator Method

Or :)

Imports System
Module Module1
	Sub Main()
		Dim myArr(5, 6, 7) As Integer
		Dim counter As Integer = 0

		For Each i32 As Integer In myArr
			Console.WriteLine("[{0}] {1}", counter , i32)

			counter += 1
		Next

		Console.ReadKey()
	End Sub
End Module


This post has been edited by n8wxs: 30 January 2009 - 06:09 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1