School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
You're Browsing As A Guest! Register Now...
Become an Expert!

Join 353,816 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,498 people online right now.Registration is fast and FREE... Join Now!



How to get the values from array's dimensions

52 Weeks of Code Challenge: WPF

Week #10 of the 52 Weeks of Code Challenge is WPF. If you're a .NET programmer, you should give it a shot. Click Here!
Page 1 of 1

How to get the values from array's dimensions The quantity of the array's dimensions are also unknown. Rate Topic: -----

#1 fiaolle  Icon User is offline

  • New D.I.C Head
  • Pip

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


Dream Kudos: 0

Posted 29 January 2009 - 12: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
Was This Post Helpful? 0
  • +
  • -


#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • Icon

Reputation: 334
  • View blog
  • Posts: 2,097
  • Joined: 06-January 08


Dream Kudos: 0

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

Posted 29 January 2009 - 02: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 - 02:55 PM

Was This Post Helpful? 0
  • +
  • -

#3 fiaolle  Icon User is offline

  • New D.I.C Head
  • Pip

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


Dream Kudos: 0

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

Posted 30 January 2009 - 01: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
  • PipPip

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


Dream Kudos: 0

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

Posted 30 January 2009 - 02:18 AM

Oops, posting in the wrong place.

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

Was This Post Helpful? 0
  • +
  • -

#5 chrixko  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 8
  • View blog
  • Posts: 53
  • Joined: 25-November 08


Dream Kudos: 0

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

Posted 30 January 2009 - 02: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
  • PipPip

Reputation: 2
  • View blog
  • Posts: 119
  • Joined: 04-December 08


Dream Kudos: 0

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

Posted 30 January 2009 - 02: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

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • Icon

Reputation: 334
  • View blog
  • Posts: 2,097
  • Joined: 06-January 08


Dream Kudos: 0

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

Posted 30 January 2009 - 04: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 - 05:09 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month