I am interested in advices how to pass variables to subroutines.
As i understand i regulary pass values.
So gosub>subroute1,text,9
will pass "text" and "9" to srt>subroute1...
Aside from using global scope variables, is there way to pass variable to subr.
Or array....
For example I want to pass value of %list_5% variable (member of array).
What is sintax to do it if it is possible?
i can not pass it as gosub>srt1,%list_5% .. or ... gosub>srt1,list_5
Or gosub>srt1,{%list_5%}
So what is current best way of doing this?
I want to use subroutine as appendix for regular command set
passing variable to subroutine
Moderators: Dorian (MJT support), JRL
-
- Junior Coder
- Posts: 21
- Joined: Thu Mar 10, 2011 6:49 pm
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I'm not sure why you say you can't pass the array variable. E.g. this works fine:
Have I misunderstood the question?
Code: Select all
GetFileList>%USERDOCUMENTS_DIR%\*.*,list,CRLF
Separate>list,CRLF,files
GoSub>test,files_5
SRT>test
MessageModal>test_var_1
END>test
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
No, you didnot.
I looked in help,only value passing is mentioned.
So notation is
parameter of subroutine is checked if it is var or array then if it is var or array is passed, or at the end, value as text or number is passed.
Is that right?
gosub>srt1,param
>if param is var, then var is passed
>if param is array, then arrah is passed
>if nothing above, "param" is passed
I looked in help,only value passing is mentioned.
So notation is
parameter of subroutine is checked if it is var or array then if it is var or array is passed, or at the end, value as text or number is passed.
Is that right?
gosub>srt1,param
>if param is var, then var is passed
>if param is array, then arrah is passed
>if nothing above, "param" is passed
-
- Junior Coder
- Posts: 21
- Joined: Thu Mar 10, 2011 6:49 pm
array and array element
Sorry,but i must inform others that passing array as variable do not work in MS.
You can assign in main program one array through another, but you can pass to subroutine only one element of array, not array by itself.
So if question was can ARRAY be passed to subroutine, answer is not, yes , becouse one element of array can be passed to subroutine.
I did not manage to pass array, but something strange happened.
will result in existance files="pera"
files_1,.......files_123.....
So in the same time exist array files and variable files
---------------------------------------
Other strange thing happened also.
When you call srt test with parameter that is array,
will give number of array elements, but i can not access any of them.
------------------------------------------------
Here is some test code where you can see that test_count at breakpoint is equal as number of elements of array, but array is not passed.
short version
test_count has global scope, and that is problem to consider.
You can assign in main program one array through another, but you can pass to subroutine only one element of array, not array by itself.
So if question was can ARRAY be passed to subroutine, answer is not, yes , becouse one element of array can be passed to subroutine.
I did not manage to pass array, but something strange happened.
Code: Select all
GetFileList>%SYS_DIR%\*.*,list,CRLF
Let>files="pera"
Separate>list,CRLF,files
files_1,.......files_123.....
So in the same time exist array files and variable files
---------------------------------------
Other strange thing happened also.
When you call srt test with parameter that is array,
Code: Select all
ArrayCount>test_Var,test_count
------------------------------------------------
Here is some test code where you can see that test_count at breakpoint is equal as number of elements of array, but array is not passed.
Code: Select all
Let>k=1
Let>line=""
Let>tekst={""}
While>%line%<EOF>%SCRIPT_DIR%\..\DATA\proba.txt,k,line
if>%line%=##EOF##,ende
Separate>%line%,;,niz
ArrayCount>niz,niz_count
MessageModal>niz_count
Let>tttt=0
Repeat>tttt
add>tttt,1
Let>broj=niz_%tttt%
ConCat>tekst,{%broj%}
ConCat>tekst,{%CRLF%}
Until>tttt=%niz_count%
MessageModal>tekst
GoSub>test,niz
srt>test
Let>tekst={""}
ArrayCount>test_Var,test_count
Let>nniz=test_Var
ArrayCount>test_Var,test_count
**BREAKPOINT**
Let>tt=0
Repeat>tt
add>tt,1
Let>broj=test_Var_%tt%
ConCat>tekst,{%broj%}
ConCat>tekst,{%CRLF%}
Until>tt=%niz_count%
MessageModal>tekst
END>test
EndWhile
Label>ende
Code: Select all
Let>line="ksfefesgdsfs;sfesfefsefesf;sefsefgbfgsef;efesfeegefg;efesfsef"
Separate>%line%,;,niz
ArrayCount>niz,niz_count
MessageModal>niz_count
GoSub>test,niz
srt>test
ArrayCount>test_Var_1,test_count
**BREAKPOINT**
Let>nniz=test_Var_1
ArrayCount>nniz,nniz_count
END>test
Last edited by katalonija2 on Tue Apr 12, 2011 10:47 am, edited 1 time in total.
-
- Junior Coder
- Posts: 21
- Joined: Thu Mar 10, 2011 6:49 pm
-
- Junior Coder
- Posts: 24
- Joined: Tue Sep 15, 2009 3:20 pm
Arrays as a passed variable
Try this Syntax:
VARIABLE_%COUNTER%
I use this w/o the {} to import my variables. MS has done everything I can imagine so far.
You may want to read the variable into another variable first.
If you decide to send multiple items from your array to the subroutine I would try something like this:
Let>AddnlArrayItem=Variable_%LoopCounter%
Let>NewVariable=%NewVariable%,%AddnlArrayItem%
Then send to the subroutine using this syntax once your loop has added all the array items you wish sent.
gosub>srt1,%NewVariable%
Hope that helps.
VARIABLE_%COUNTER%
I use this w/o the {} to import my variables. MS has done everything I can imagine so far.
You may want to read the variable into another variable first.
If you decide to send multiple items from your array to the subroutine I would try something like this:
Let>AddnlArrayItem=Variable_%LoopCounter%
Let>NewVariable=%NewVariable%,%AddnlArrayItem%
Then send to the subroutine using this syntax once your loop has added all the array items you wish sent.
gosub>srt1,%NewVariable%
Hope that helps.
I think I can automate that!