SRT>SUpdt1
Let>SUpdt_VCnt=0
ArrayCount>SUpdt1_Var,SUpdt_VCnt
MessageModal>SUpdt_VCnt
END>SUpdt1
GoSub>SUpdt1,3057,8003057,TestStr1,TestStr2
GoSub>SUpdt1,1117,5001117,TestStr
GoSub>SUpdt1,3136,5003136,TestStr1,TestStr2,TestStr3
GoSub>SUpdt1,3097,5003097,TestStr1,TestStr2
GoSub>SUpdt1,1117,5001117,TestStr1
Results: 4, 4, 5, 5, 5
What I expected: 4, 3, 5, 4, 3
Am I doing something wrong?
Thanks!
ArrayCount_ Unexpected values
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I'm not entirely sure what you're trying to do here. ArrayCount requires a variable that represents an array. You're passing integer values to it, and I don't see any arrays in your code. Furthermore you're referring to something called SUpdt1_Var which doesn't exist either. Is there some of your code missing?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I ran the code, and it is interesting.
It counts the number of parameters passed into the SRT.
What I see happening is that variables which are created when the GoSub> happens don't get destroyed after the subroutine finishes.
Then next time when the SRT is called with fewer parameters, the previously created parm variables still exist.
Does seem like a problem.
It counts the number of parameters passed into the SRT.
What I see happening is that variables which are created when the GoSub> happens don't get destroyed after the subroutine finishes.
Then next time when the SRT is called with fewer parameters, the previously created parm variables still exist.
Does seem like a problem.
Arrays in MS are dynamic in the sense that they can only 'grow'. This is true for parameters too. The call with the largest num of pars wins.
I have used 2 techniques to cope with variable length arrays or a variable number of parameters:
1. Set localvars to one in a SRT and then create the array within the subroutine. When exiting the array is gone.
2. At the end of a subroutine, reset the the value of the parameter name to its name and at the beginning test that to see if the par is present
so at the end insert:
let>SUpdt1_Var_1={"SUpdt1_Var_1"}
and then at the start of the SRT test all variable pars against their own name:
if>SUpdt1_Var_1={"SUpdt1_Var_1"}
See next posting for a better solution.
It's a trick but it does allow a variable number of parameters. The array count does not work though, have to do that manually.
-----edit
changed syntax error }" in "}
See next posting fro a much better solution: set locavars to one at the callers level. Interesting!
I have used 2 techniques to cope with variable length arrays or a variable number of parameters:
1. Set localvars to one in a SRT and then create the array within the subroutine. When exiting the array is gone.
2. At the end of a subroutine, reset the the value of the parameter name to its name and at the beginning test that to see if the par is present
so at the end insert:
let>SUpdt1_Var_1={"SUpdt1_Var_1"}
and then at the start of the SRT test all variable pars against their own name:
if>SUpdt1_Var_1={"SUpdt1_Var_1"}
See next posting for a better solution.
It's a trick but it does allow a variable number of parameters. The array count does not work though, have to do that manually.
-----edit
changed syntax error }" in "}
See next posting fro a much better solution: set locavars to one at the callers level. Interesting!
Last edited by Dick99999 on Tue Oct 12, 2010 4:58 pm, edited 3 times in total.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Ah, now I see what you were trying to do. Sorry.
You could use localvars. That way each subroutine has it's own parm array:
You could use localvars. That way each subroutine has it's own parm array:
Code: Select all
SRT>SUpdt1
Let>SUpdt_VCnt=0
ArrayCount>SUpdt1_Var,SUpdt_VCnt
MessageModal>SUpdt_VCnt
END>SUpdt1
Let>LOCALVARS=1
GoSub>SUpdt1,3057,8003057,TestStr1,TestStr2
GoSub>SUpdt1,1117,5001117,TestStr
GoSub>SUpdt1,3136,5003136,TestStr1,TestStr2,TestStr3
GoSub>SUpdt1,3097,5003097,TestStr1,TestStr2
GoSub>SUpdt1,1117,5001117,TestStr1
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Junior Coder
- Posts: 21
- Joined: Thu Mar 10, 2011 6:49 pm
COUNT
Is there variable subroutine_Var_count created?
I was told by someone somewhere that all array func has name_count variable created.
I was told by someone somewhere that all array func has name_count variable created.