PC Review


Reply
Thread Tools Rate Thread

Creating matrices and subsequently prosess those in a loop

 
 
Rob
Guest
Posts: n/a
 
      22nd Oct 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      23rd Oct 2007
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
>

 
Reply With Quote
 
Rob
Guest
Posts: n/a
 
      23rd Oct 2007
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" <(E-Mail Removed)> schreef in bericht
news:7B14233A-3CF5-42C6-AB7D-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using ParseControl and Subsequently Getting Specific Control Type Jordan S. Microsoft ASP .NET 1 23rd May 2008 08:20 PM
Printer prints document once but then fails to subsequently print =?Utf-8?B?15DXkdeZ?= Windows XP Print / Fax 0 11th Feb 2007 11:04 PM
how to end a prosess =?Utf-8?B?RWRkaWU=?= Windows XP General 1 12th Nov 2006 06:34 PM
how to end e prosess =?Utf-8?B?RWRkaWU=?= Windows XP Help 0 12th Nov 2006 04:33 PM
csrss prosess running twice. Consuming 99% of CPU Jim Microsoft Windows 2000 1 11th Dec 2003 02:31 PM


Features
 

Advertising
 

Newsgroups
 


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