VAREXPLICIT=1 and Array Access

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
KTT
Newbie
Posts: 13
Joined: Thu Jul 02, 2009 10:26 pm

VAREXPLICIT=1 and Array Access

Post by KTT » Mon Aug 02, 2010 8:50 am

I code with VAREXPLICIT=1 in hopes of keeping things clearer with respect to variable expansion in MacroScheduler.

This approach seems to be going well, until I needed to access an array element. I couldn't find a way to do so while VAREXPLICIT=1, so had to set VAREXPLICIT=0, assign the array element to a normal variable, then reset VAREXPLICIT:

Code: Select all

Let>OLDVAREXPLICIT=%VAREXPLICIT%
Let>VAREXPLICIT=0
Let>kX=XArr_%k%
Let>kY=YArr_%k%
Let>VAREXPLICIT=%OLDVAREXPLICIT%
Concat>RETVAL,"x":%kX%%COMMA%"y":%kY%
This is very ugly, and is necessary since the %var% expansion is REQUIRED when VAREXPLICIT=1 and is not nest-able. That is, %XArr_%k%% doesn't work to access XArr[k].

Is this really the only way to access an array element while VAREXPLICIT=1?

Thanks in advance.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Aug 03, 2010 4:12 am

I have almost never used VarExplicit so I set up a sample of your script to run through and see what was what. The answer to your question is YES, VarExplicit needs to be set to zero in order to resolve arrayed variables.

But then I made an odd discovery. I'm guessing there's a logical explanation but so far, I'm not seeing it.

If I run the following script in the editor and watch the watch list I see VarExplicit get set to "1" then the next few variables get set to their values as expected. But when I press F8 for the line:
Let>OLDVAREXPLICIT=%VAREXPLICIT%
I see the variable OLDVAREXPLICIT get set to "0" when I expect it to become "1".

What am I missing?

Code: Select all

Let>VAREXPLICIT=1
Let>XArr_1=23.45
Let>YArr_1=54.32
Let>k=1
Let>RETVAL=
Let>COMMA=,

Let>OLDVAREXPLICIT=%VAREXPLICIT%
Let>VAREXPLICIT=0
Let>kX=XArr_%k%
Let>kY=YArr_%k%
Let>VAREXPLICIT=%OLDVAREXPLICIT%
Concat>RETVAL,"x":%kX%%COMMA%"y":%kY%

KTT
Newbie
Posts: 13
Joined: Thu Jul 02, 2009 10:26 pm

Post by KTT » Tue Aug 03, 2010 7:13 am

Your are right, JRL. My script doesn't work as I intended.

As you pointed out, it seems that VAREXPLICIT is a write only variable. It always returns 0 regardless of its true value, which you can set with LET>

My original snippet was meant to be as side-effect free as possible, by trying to remember then reset VAREXPLICIT to its original value. Due to the fact that %VAREXPLICIT% doesn't return its true value but always 0, the snippet exits with the wrong VAREXPLICIT value of 0.

Thinking about it again, since the only reason I'm jumping through hoops to get the array element value in the first place is because VAREXPLICIT=1, we can simply set VAREXPLICIT=1 when we exit the snippet. So the revised code is thus:

Code: Select all

Let>VAREXPLICIT=1
Let>XArr_1=23.45
Let>YArr_1=54.32
Let>k=1
Let>RETVAL=
Let>COMMA=,

Let>VAREXPLICIT=0
Let>kX=XArr_%k%
Let>kY=YArr_%k%
Let>VAREXPLICIT=1
Concat>RETVAL,"x":%kX%%COMMA%"y":%kY%

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

Post by Marcus Tettmar » Tue Aug 03, 2010 8:26 am

Hi,

It should be possible to retrieve the value of VAREXPLICIT so I have made a note of this on the current to-do list.

It is true that handling embedded array type variables is awkward when using VAREXPLICIT and it needs to be turned off, since array type variables are in fact variables embedded in others.

The longer term plan is to work towards creating real array structures to avoid this problem and add further capabilities.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Tue Aug 03, 2010 8:24 pm

mtettmar wrote:The longer term plan is to work towards creating real array structures to avoid this problem and add further capabilities.
Sounds good.

Capabilities I'd really like to see include:

1. A way to instantly display the data inside an array structure to a user. I use MS to run queries and the database returns 4000 rows in only 10 seconds. At that point all the data is inside array variables in MS but there is NO FAST WAY for me to display that data to the user. Delphi has a DB Grid control... if we could add a DB Grid Control to a dialog and point it at the array that contains our data... that would be very nice (and I would hope... fast).

As it is, I have a loop that re-formats the data into either a csv file or an html web page and when done, the macro opens the file in either Excel or a browser. The problem is, it takes 6 minutes to reformat the data... just to get that data to the point that I can display it. A user will wait 10 seconds no problem... but 6 minutes is pushing it... even with a progress bar on my dialog and a text label that asks them to please wait.

Anything that could be done to speed up that reformatting loop would be great. I know that creating one HUGE variable and then writing that to disk in one shot is a BAD approach for large result sets... it gets slower and slower with each loop and takes far longer than 6 minutes. My loop now is writing each line to disk as it processes which is faster but still not fast enough.

2. Considering that exposing the Delphi DB Grid Control may not be happening soon (or ever)... please consider (or at least investigate if it is even possible) to create a version of the DBQuery command that directly creates one or both of these:
  • a) a csv file of this standard form:

    "col 1 data","col 2 data"
    "col 1 data","col 2 data"

    b) a html file (fragment) of this standard form:

    col 1 datacol 2 data
    col 1 datacol 2 data
If such a command is possible (DBQueryToFile> perhaps?) then this might allow one to create the file very quickly and therefore display the results to the user in maybe 15 seconds... verses the six minute wait they currently go through.

Marcus and all... your thoughts?
Edit: Wed Aug 14, 2010 wrote:More detail can be found in the following post under Enhancement Suggestions:

DBQuery direct to file
http://www.mjtnet.com/forum/viewtopic.php?t=6166
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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