Array (?) help

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
JMusic
Newbie
Posts: 3
Joined: Wed Dec 30, 2009 6:39 pm

Array (?) help

Post by JMusic » Wed Dec 30, 2009 7:25 pm

I am pretty sure that I am simply not understanding how something works, but I have run into a problem I cannot find a way around.

My code, stripped down to the basics:
MaxCount is passed as an option.

Code: Select all


let>Countup=1
Repeat>Countup
let>Countup=Countup+1
dderequest>Excel,MyFile.xls,R%Countup%C1,celldata_%Countup%,10
until>Countup,MaxCount

blah blah blah

let>Countitup=1
repeat>Countitup
let>Countitup=Countitup+1
send>celldata_%Countitup%
until>Countitup,MaxCount

I can ddepoke celldata_%Countup% and celldata_%Countitup% (both should reference the same data, essentially celldata_1/2/3/4/etc) back to Excel and get the right value, but I am outputting to something else that has no dde ability and "send" sends the first value every time. I have a feeling this is an array issue and/or an issue of having a variable name made with a secondary variable. Any hints appreciated.

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

Post by jpuziano » Wed Dec 30, 2009 8:02 pm

Hi JMusic,

Single step through it with the debugger and watch the values in the variables.

Here's a link Marcus recently posted that may help...

How to use the DEBUGGER to solve your problem

...and let us know what you find.

Take care
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 - :-)

JMusic
Newbie
Posts: 3
Joined: Wed Dec 30, 2009 6:39 pm

Post by JMusic » Wed Dec 30, 2009 8:19 pm

Already did that. The variables are all being assigned correctly.

However, I do think I have found the problem. A line that I stripped out seems to be resetting the variable rather than what it is intended to do.

The culprit:

stringreplace>celldata_%Countitup%,CRLF,,celldata_%Countitup%

That doesn't do what I would expect it to do. I can work around that. I would still like what this line does to happen, but if it completely breaks the variable it's not worth it.

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

Post by jpuziano » Wed Dec 30, 2009 8:57 pm

JMusic wrote:The culprit:

stringreplace>celldata_%Countitup%,CRLF,,celldata_%Countitup%

That doesn't do what I would expect it to do. I can work around that. I would still like what this line does to happen, but if it completely breaks the variable it's not worth it.
I'm glad you have a workaround... but could you please post a few lines of code with an example that shows how it breaks a variable? Please include some sample data, nothing big, just the bare minimum to show the problem.

If the StringReplace> command has issues, I'm sure Marcus would like to fix it... and your example would let him replicate the problem.

Thanks for posting and take care...
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 - :-)

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

Post by JRL » Wed Dec 30, 2009 11:55 pm

There are Macro Scheduler functions that don't deal with arrays directly. I've found the only safe way to deal with arrayed variables in a loop is to use Let> to create a benign variable and use that variable in the loop.

for example:
let>Countup=1
Repeat>Countup
let>Countup=Countup+1
dderequest>Excel,MyFile.xls,R%Countup%C1,celldata_%Countup%,10
until>Countup,MaxCount

blah blah blah

let>Countitup=1
repeat>Countitup
let>Countitup=Countitup+1
Let>value=celldata_%Countitup%
send>%value%

until>Countitup,MaxCount

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Dec 31, 2009 12:17 am

Before you use Send> have you done a SetFocus>? Where is the Send output going to?

Also, at this point, just before Send> you should check %value% and make sure it is correct. You could do this Single Step or with MessageModal> for test purposes, then remove it or comment it out in the final script.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

JMusic
Newbie
Posts: 3
Joined: Wed Dec 30, 2009 6:39 pm

Post by JMusic » Thu Feb 11, 2010 7:03 pm

JRL wrote:There are Macro Scheduler functions that don't deal with arrays directly. I've found the only safe way to deal with arrayed variables in a loop is to use Let> to create a benign variable and use that variable in the loop.

for example:
let>Countup=1
Repeat>Countup
let>Countup=Countup+1
dderequest>Excel,MyFile.xls,R%Countup%C1,celldata_%Countup%,10
until>Countup,MaxCount

blah blah blah

let>Countitup=1
repeat>Countitup
let>Countitup=Countitup+1
Let>value=celldata_%Countitup%
send>%value%

until>Countitup,MaxCount
Many thanks for this tip. I have run into this problem again (and can't just get rid of the line this time) and came back to see if there were any other comments and this is the perfect, simple and logical solution. And I'm kicking myself for not thinking of it on my own. :oops:

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