Help with loops?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Phobosares
Newbie
Posts: 2
Joined: Fri Jun 22, 2012 3:57 pm

Help with loops?

Post by Phobosares » Fri Jun 22, 2012 4:07 pm

Hey guys, I am currently evaluating the standard edition of the Macro Scheduler 13 software.

I want to make a script that loops through excel columns, and each time a row is done the next row is done. I managed to only get a single row finished, however for some reason the loops will not commence to row 2 until conditions are met.

I am trying to write a script similar to what I did in python. In python, with embedded for loops, I could make the embedded loop iterate to 8 before iterating the first loop once.

For a python code example:

Code: Select all

for Row in range(0, 5):
     for Column in range(0, 8):
          print(Row, Column)
Basically, this example loops rows and columns. Before the row value can turn to 1, the column value has to iterate to 8 before row can become 1.

I am trying to replicate this in the script editor, but with the absence of for loops, how do I do it?

Specifically, in Excel; I was to use the Getcell and Setcell functions created in the script editor to copy and paste between two instances of excel.

Here is my failed attempt at trying to get it to work: NOTE: The code isn't pasting correctly into the box below.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1


XLOpen>C:\Documents and Settings\abrideau\My Documents\PracticeIn.xlsx,1,xlBookIn
XLOpen>C:\Documents and Settings\abrideau\My Documents\PracticeOut.xlsx,1,xlBookOut

XLGetSheetDims>xlBookIn,Sheet1,nRowCount,nColCount

Let>XColVal=2
Let>XRowVal=1

  While>XRowVal<5>XRowVal=XRowVal+1
  XLGetCell>xlBookIn,Sheet1,XRowVal,XColVal,strCell
  XLSetCell>xlBookOut,Sheet1,XRowVal,XColVal,strCell,scResult


  EndWhile

  While>XColVal<8>XRowVal=2
  Let>XColVal=XColVal+1
  XLGetCell>xlBookIn,Sheet1,XRowVal,XColVal,strCell
  XLSetCell>xlBookOut,Sheet1,XRowVal,XColVal,strCell,scResult

  EndWhile


Some help would be greatly appreciated.

Thanks.

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Jun 22, 2012 4:27 pm

Run this and see if it loops like you want...

Code: Select all


Let>RowCnt=1
Let>ColMax=8
Let>RowMax=5

While>RowCnt<%RowMax%+1
  Let>ColCnt=1
  While>ColCnt<%ColMax%+1
    MDL>Row: %RowCnt%, Col: %ColCnt%
    Let>ColCnt=ColCnt+1
  EndWhile
  Let>RowCnt=RowCnt+1
EndWhile
Thanks,
Jerry

[email protected]

Phobosares
Newbie
Posts: 2
Joined: Fri Jun 22, 2012 3:57 pm

Post by Phobosares » Fri Jun 22, 2012 4:36 pm

That is perfect, thanks! I think I need to spend more time reading the user manual.

But can you explain what the "%" symbols do?

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