ArrayCount_ Unexpected values

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

ArrayCount_ Unexpected values

Post by jbas » Tue Oct 12, 2010 3:02 am

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!

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Oct 12, 2010 8:31 am

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?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Oct 12, 2010 12:15 pm

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.

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Tue Oct 12, 2010 12:26 pm

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!
Last edited by Dick99999 on Tue Oct 12, 2010 4:58 pm, edited 3 times in total.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Oct 12, 2010 12:53 pm

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:

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?

jbas
Junior Coder
Posts: 29
Joined: Tue Dec 15, 2009 4:59 pm

Post by jbas » Tue Oct 12, 2010 8:10 pm

Thank-you for the responses! Setting LOCALVARS worked well for me in this instance.

katalonija2
Junior Coder
Posts: 21
Joined: Thu Mar 10, 2011 6:49 pm

COUNT

Post by katalonija2 » Sat Mar 26, 2011 4:12 am

Is there variable subroutine_Var_count created?
I was told by someone somewhere that all array func has name_count variable created.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts