Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Creating matrices and subsequently prosess those in a loop

Hello FellowDevelopers,

I want to define a set of arrays with the same structure but with the diferent contents. The content of each array has to be processed. The arrays vary in count, sometimes 2, sometimes it's 6. So I want to repeat processing all arrays in a loop. By naming all arrays subsequently (Arr1, Arr2 etc) with a counter I can see what array I have to process.


I wrote this code with two subroutines. The problem is in the second part, (CopyOne), where I cannot use the name of the array. Any ideas?

Rob




Option Base 1
Public Arr1 As Variant
Public Arr2 As Variant

Sub CopyAll()

' Needed counters
Dim intArrNr As Integer
Dim intArrCount As Integer
intArrCount = 2

' Here I declare two arrays and with each array the same things have to be copied.
Arr1 = Array("A", "B")
Arr2 = Array("C", "D")

' Do somthing with each of the arrays
For intArrNr = 1 To intArrAant
CopyOne (intArrNr)
Next

End Sub

Sub CopyOne(Nr)

Dim strArrName
strArrName = "Arr" & Nr

' Now, normally if I want to do something with a part of the array I do this:
' msgbox Arr1(1) and it says A
' msgbox Arr2(2) and it says D

' But now I want to do Msgbox strArrName(1)
' Tht is: take the value IN strArrName,
' which is "Arr1", and use it as the name of the array to show the first element
' How can I solve this?

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Creating matrices and subsequently prosess those in a loop

In cases like this, I fall back on the old timey practice of developing a
flow chart to see if I am really doing what I want to do. I can also figure
out what my alternatives are and usually, although not always, come up with
the optimal solution.
You could declare your arrays again, or you could incorporate that procedure
into the other one. There are probably several other approaches that would
become evident if the objectives were put in flow chart form.


"Rob" wrote:

Hello FellowDevelopers,

I want to define a set of arrays with the same structure but with the diferent contents. The content of each array has to be processed. The arrays vary in count, sometimes 2, sometimes it's 6. So I want to repeat processing all arrays in a loop. By naming all arrays subsequently (Arr1, Arr2 etc) with a counter I can see what array I have to process.


I wrote this code with two subroutines. The problem is in the second part, (CopyOne), where I cannot use the name of the array. Any ideas?

Rob




Option Base 1
Public Arr1 As Variant
Public Arr2 As Variant

Sub CopyAll()

' Needed counters
Dim intArrNr As Integer
Dim intArrCount As Integer
intArrCount = 2

' Here I declare two arrays and with each array the same things have to be copied.
Arr1 = Array("A", "B")
Arr2 = Array("C", "D")

' Do somthing with each of the arrays
For intArrNr = 1 To intArrAant
CopyOne (intArrNr)
Next

End Sub

Sub CopyOne(Nr)

Dim strArrName
strArrName = "Arr" & Nr

' Now, normally if I want to do something with a part of the array I do this:
' msgbox Arr1(1) and it says A
' msgbox Arr2(2) and it says D

' But now I want to do Msgbox strArrName(1)
' Tht is: take the value IN strArrName,
' which is "Arr1", and use it as the name of the array to show the first element
' How can I solve this?

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Creating matrices and subsequently process those in a loop

Hello,

it isn't that complicated that I have to put it in a flowchart. It works if
I address the arrays individually. The question is how I can get the value
in the variable to work as a NAME for the array.

Ok, even more easy code

Sub WorkWithArray()

Dim Arr1 As Variant
Dim Arr2 As Variant
Dim strArrName
Dim strArrNr
Dim intArrCount

' Here I declare two arrays and with each array I have to do something
Arr1 = Array("A", "B")
Arr2 = Array("C", "D")
' Fill counters
strArrNr = 1
intArrCount = 2
strArrName = "Arr" & Nr ' Nr = 1, so strArrName = "Arr1"

' Repeat doing something with each of the arrays
For intArrNr = 1 To intArrCount
Msgbox strArrName(1) ' But THIS doesn't work. How do I get
the CONTENT in the variable work as the Array-designation - Arr1(1) - ?
strArrNr = strArrNr + 1
strArrName = "Arr" & Nr
Next

End sub



Rob


"JLGWhiz" schreef in bericht
...
In cases like this, I fall back on the old timey practice of developing a
flow chart to see if I am really doing what I want to do. I can also
figure
out what my alternatives are and usually, although not always, come up
with
the optimal solution.
You could declare your arrays again, or you could incorporate that
procedure
into the other one. There are probably several other approaches that
would
become evident if the objectives were put in flow chart form.


"Rob" wrote:

Hello FellowDevelopers,

I want to define a set of arrays with the same structure but with the
diferent contents. The content of each array has to be processed. The
arrays vary in count, sometimes 2, sometimes it's 6. So I want to repeat
processing all arrays in a loop. By naming all arrays subsequently (Arr1,
Arr2 etc) with a counter I can see what array I have to process.


I wrote this code with two subroutines. The problem is in the second
part, (CopyOne), where I cannot use the name of the array. Any ideas?

Rob




Option Base 1
Public Arr1 As Variant
Public Arr2 As Variant

Sub CopyAll()

' Needed counters
Dim intArrNr As Integer
Dim intArrCount As Integer
intArrCount = 2

' Here I declare two arrays and with each array the same things
have to be copied.
Arr1 = Array("A", "B")
Arr2 = Array("C", "D")


End Sub

Sub CopyOne(Nr)

Dim strArrName
strArrName = "Arr" & Nr

' Now, normally if I want to do something with a part of the array I do
this:
' msgbox Arr1(1) and it says A
' msgbox Arr2(2) and it says D

' But now I want to do Msgbox strArrName(1)
' Tht is: take the value IN strArrName,
' which is "Arr1", and use it as the name of the array to show the
first element
' How can I solve this?

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with creating a loop Woodi2 Setting up and Configuration of Excel 1 April 19th 09 09:10 PM
Creating a loop JakeShipley2008 Excel Discussion (Misc queries) 1 September 8th 08 10:26 PM
Need help creating Loop Jenny B. Excel Discussion (Misc queries) 3 February 14th 07 11:26 PM
How to stop search / replace prosess in large excel worksheets palcamb Excel Programming 0 October 18th 06 01:59 PM
Creating a loop shart Excel Programming 10 December 21st 05 08:24 AM


All times are GMT +1. The time now is 04:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"