Accessing Array elements
Moderators: Dorian (MJT support), JRL
-
- Junior Coder
- Posts: 28
- Joined: Wed Jul 22, 2015 6:10 pm
- Location: A Berliner just east of Wien
Accessing Array elements
Hello,
I have a problem that drives me mad and that is with the syntax of accessing elements of an Array via a variable. Here is the extract where the problem occurs:
1) There is a file, which was previouly written by MS, with these values:
PageRow^070102^ProjectAbc^1^1^15^320^
PageRow^070102^ProjectAbc^1^1^15^320^
PageRow^070102^ProjectAbc^1^1^15^320^
and a couple of more similar rows
2) This is the code that is trying to read the last line:
SRT>msLoadCurrPageNr
ChangeDirectory>s:\MacroScheduler\LogsCurrPageNr\230629\
Let>msFileNameCurrPageNr=S:\MacroScheduler\LogsCurrPageNr\230629\ProjectAbc.txt
CSVFileToArray>msFileNameCurrPageNr,msArrCurrPagePath
Let>k=msArrCurrPagePath_count
// All of these fail
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%k%_0
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_k
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%k%
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%k%_0
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%15%_0
// The only chance is to supply an explicit Integer for the row number
// which is nonsense as I need the kfrom msArrCurrPagePath_count
Let>msArrCurrPageRowLast=msArrCurrPagePath_15_0
Let>msArrCurrPageRowLast=msArrCurrPagePath_15_0
END>msLoadCurrPageNr
How can I use a varible? The very sparse example in the doc did not help.
Best
Heinz
I have a problem that drives me mad and that is with the syntax of accessing elements of an Array via a variable. Here is the extract where the problem occurs:
1) There is a file, which was previouly written by MS, with these values:
PageRow^070102^ProjectAbc^1^1^15^320^
PageRow^070102^ProjectAbc^1^1^15^320^
PageRow^070102^ProjectAbc^1^1^15^320^
and a couple of more similar rows
2) This is the code that is trying to read the last line:
SRT>msLoadCurrPageNr
ChangeDirectory>s:\MacroScheduler\LogsCurrPageNr\230629\
Let>msFileNameCurrPageNr=S:\MacroScheduler\LogsCurrPageNr\230629\ProjectAbc.txt
CSVFileToArray>msFileNameCurrPageNr,msArrCurrPagePath
Let>k=msArrCurrPagePath_count
// All of these fail
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%k%_0
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_k
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%k%
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%k%_0
Let>msArrCurrPageRowLast=%msArrCurrPagePath%_%15%_0
// The only chance is to supply an explicit Integer for the row number
// which is nonsense as I need the kfrom msArrCurrPagePath_count
Let>msArrCurrPageRowLast=msArrCurrPagePath_15_0
Let>msArrCurrPageRowLast=msArrCurrPagePath_15_0
END>msLoadCurrPageNr
How can I use a varible? The very sparse example in the doc did not help.
Best
Heinz
- Dorian (MJT support)
- Automation Wizard
- Posts: 1379
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Accessing Array elements
Here you go (tested) :
Code: Select all
Let>msArrCurrPageRowLast=msArrCurrPagePath_%k%_0
Yes, we have a Custom Scripting Service. Message me or go here
-
- Junior Coder
- Posts: 28
- Joined: Wed Jul 22, 2015 6:10 pm
- Location: A Berliner just east of Wien
Re: Accessing Array elements
Thank you very much for the extremely quick reply
and shame on me that I did not test this variant.
Thanks and best regards
Heinz
and shame on me that I did not test this variant.
Thanks and best regards
Heinz
- Dorian (MJT support)
- Automation Wizard
- Posts: 1379
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Accessing Array elements
You're very welcome. You were almost there, you just missed that one permutation.
Yes, we have a Custom Scripting Service. Message me or go here
-
- Junior Coder
- Posts: 28
- Joined: Wed Jul 22, 2015 6:10 pm
- Location: A Berliner just east of Wien
Re: Accessing Array elements
Hello,
in the above example I had already replaced the count variable for accessing the array from something much longer to %k%, which did work with nothing else changed except the short variable name.
I encountered the same problem today at code written a few days ago but not yet used or tested.
This failed (or even worse, delivered nothing):
After changing this one line into this:
it worked. I am on the latest version 15.0.24 and AFAIK such problem did not exist in older version but I had not done much with MS in the last 8-9 months.
I am posting this only FYI and of the readers as my problem is solved.
Best regards
Heinz
in the above example I had already replaced the count variable for accessing the array from something much longer to %k%, which did work with nothing else changed except the short variable name.
I encountered the same problem today at code written a few days ago but not yet used or tested.
This failed (or even worse, delivered nothing):
Code: Select all
Let>msArrCurrPageRowLast=msArrCurrPagePath_%msArrCurrPageSize%_0
Code: Select all
Let>k=%msArrCurrPageSize%
Let>msArrCurrPageRowLast=msArrCurrPagePath_%k%_0
I am posting this only FYI and of the readers as my problem is solved.
Best regards
Heinz
-
- Junior Coder
- Posts: 28
- Joined: Wed Jul 22, 2015 6:10 pm
- Location: A Berliner just east of Wien
Re: Accessing Array elements
Hello,
I just started testing new modules, some of which were taken from older code. And I encountered the same problem with longer variable names used to access Array elements as already described above.
Only in this case I am absolutely sure that they worked long ago when I used an older version of MS (most likey that was 15.0.20 or even older).
Could this come from changes in the latest 15.0.24?
Best
Heinz
I just started testing new modules, some of which were taken from older code. And I encountered the same problem with longer variable names used to access Array elements as already described above.
Only in this case I am absolutely sure that they worked long ago when I used an older version of MS (most likey that was 15.0.20 or even older).
Could this come from changes in the latest 15.0.24?
Best
Heinz
Re: Accessing Array elements
Hello,
This works for me:
How do you define:
This works for me:
Code: Select all
CSVFileToArray>C:\Users\Christer\Desktop\msTest.txt,msArrCurrPagePath
Let>msArrCurrPageRowLast=msArrCurrPagePath_%msArrCurrPagePath_COUNT%_0
Code: Select all
%msArrCurrPageSize%
- Dorian (MJT support)
- Automation Wizard
- Posts: 1379
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Accessing Array elements
I think hagchr is on the right track there.
This works :
This doesn't.
This works :
Code: Select all
Let>msFileNameCurrPageNr=d:\00000\ProjectAbc.txt
CSVFileToArray>msFileNameCurrPageNr,msArrCurrPagePath
Let>msArrCurrPageSize=3
Let>msArrCurrPageRowLast=msArrCurrPagePath_%msArrCurrPageSize%_0
Code: Select all
Let>msFileNameCurrPageNr=d:\00000\ProjectAbc.txt
CSVFileToArray>msFileNameCurrPageNr,msArrCurrPagePath
//Let>msArrCurrPageSize=3
Let>msArrCurrPageRowLast=msArrCurrPagePath_%msArrCurrPageSize%_0
Yes, we have a Custom Scripting Service. Message me or go here
-
- Junior Coder
- Posts: 28
- Joined: Wed Jul 22, 2015 6:10 pm
- Location: A Berliner just east of Wien
Re: Accessing Array elements
Thank you in advance.
I cannot care about this before tomorrow earliest - and I will then post my real code.
Tx for the moment!
I cannot care about this before tomorrow earliest - and I will then post my real code.
Tx for the moment!
Re: Accessing Array elements
ooops dupe post
Last edited by Krep on Mon Sep 11, 2023 7:11 pm, edited 1 time in total.
Re: Accessing Array elements
Hello! Similar question along these lines... Is it possible to assign or retrieve a value from/to an array element inside a complex expression?
For example:
Let>Stack_1=A
Let>Stack_2=B
Let>Ptr=2
//Let>TempVar=Stack_%Ptr%
//StringReplace>A;B;C;D,%TempVar%;,,holder
StringReplace>A;B;C;D,%Stack_%Ptr%%;,,holder
the desired output is for holder=A;C;D
I know I can simply use another statement by assigning a temporary variable such as uncommenting the two lines in the middle!! But I would rather not because this is a simplified version of my actual code which has many passed variables and is much more complicated; it would be nice to be able to handle it in a single complex line instead of multiple temporary variables... Just checking if there's an easier way...
I've tried variations such as:
StringReplace>A;B;C;D,{%Stack_%Ptr%%};,,holder
StringReplace>A;B;C;D,%{Stack_%Ptr%}%;,,holder
StringReplace>A;B;C;D,{%("Stack_"%Ptr%)%+";"},,holder
For example:
Let>Stack_1=A
Let>Stack_2=B
Let>Ptr=2
//Let>TempVar=Stack_%Ptr%
//StringReplace>A;B;C;D,%TempVar%;,,holder
StringReplace>A;B;C;D,%Stack_%Ptr%%;,,holder
the desired output is for holder=A;C;D
I know I can simply use another statement by assigning a temporary variable such as uncommenting the two lines in the middle!! But I would rather not because this is a simplified version of my actual code which has many passed variables and is much more complicated; it would be nice to be able to handle it in a single complex line instead of multiple temporary variables... Just checking if there's an easier way...
I've tried variations such as:
StringReplace>A;B;C;D,{%Stack_%Ptr%%};,,holder
StringReplace>A;B;C;D,%{Stack_%Ptr%}%;,,holder
StringReplace>A;B;C;D,{%("Stack_"%Ptr%)%+";"},,holder
- Dorian (MJT support)
- Automation Wizard
- Posts: 1379
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Accessing Array elements
Your commented out method is the correct way. You can't use complex expressions with StringReplace.
Yes, we have a Custom Scripting Service. Message me or go here