Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
Dynamic array assign
Maybe I am just having a Friday moment but is it possible to dynamically allocate an numbered array as a variable? Let me explain...
Basically I have multiple arrays I want to do the same set of routines on. I want to do something like:
The concept of BaseArray:CurrArray works with things like RowExists, Xlate, Read Rec, etc... because they want the string label, not the array itself.
In a nutshell I want to evaluate the concatentation before the assignment so that it then assigns the Array itself, not the string name it would otherwise automatically revert to....
Basically I have multiple arrays I want to do the same set of routines on. I want to do something like:
BaseArray = "MY_ARRAY_"
ArrayCnt = Dcount(......)
For CurrArray = 1 to ArrayCnt
FocusArray = BaseArray:CurrArray ; // Here I want FocusArray equal to the arrray MY_ARRAY_1, not the string.
//Do some stuff here to FocusArray and then set it back, doing the reverse of the line above.
Next CurrArray
The concept of BaseArray:CurrArray works with things like RowExists, Xlate, Read Rec, etc... because they want the string label, not the array itself.
In a nutshell I want to evaluate the concatentation before the assignment so that it then assigns the Array itself, not the string name it would otherwise automatically revert to....
Comments
In other words, the number of arrays is dependent on some other variable?
Set_Property(@Window, '@MY_ARRAY_1', Array1) Set_Property(@Window, '@MY_ARRAY_2', Array2)
Then in your loop you would do something like this:
BaseArray = "MY_ARRAY_" ArrayCnt = Dcount(......) For CurrArray = 1 to ArrayCnt FocusArray = Get_Property(@Window, '@' : BaseArray:CurrArray) //Do some stuff here to FocusArray and then set it back, doing the reverse of the line above. Next CurrArray
Dim Arrays(100) ; // Either some arbitrary large number or a known number ArrayCnt = Dcount(......) For CurrArray = 1 to ArrayCnt FocusArray = Arrays(CurrArray) //Do some stuff here to FocusArray and then set it back, doing the reverse of the line above. Next CurrArray
Well at the moment it is actually 6. I worked around my problem by just replicating the code 6 times. However I wanted to trim the code, make it more maintainable, and future proof it a bit.
@DonBakke
Unfortunately is is not form based otherwise I could have done that. Using UDPs in forms is one of my favorite things to do! This is just a store procedure that I am trying to build up to do a little background maintenance as a side project. I guess I could always create a NDW Maintenance form that is not menu driven to control it....
You don't need a form that way, nor replication of the code.
BaseArray = MY_ARRAY_1:@fm: MY_ARRAY_2:@fm: MY_ARRAY_3:@fm: MY_ARRAY_4:@fm: MY_ARRAY_5:@fm: MY_ARRAY_6 ArrayCnt = Dcount(BaseArray, @fm) ; // of course you know this number already but a little bit of future proofing For CurrArray = 1 to ArrayCnt FocusArray = BaseArray<CurrArray> ; // Here I want FocusArray equal to the arrray MY_ARRAY_1, not the string. //Do some stuff here to FocusArray and then set it back, doing the reverse of the line above. BaseArray<CurrArray> = FocusArray Next CurrArray
I wrote and posted my reply before I saw your followups!
Gives me something to recode over the weekend ;-)
You are both Legends!