Looping Problem

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Looping Problem

Post by RNIB » Tue Sep 12, 2017 3:54 pm

I've never been great on looping and in this particular macro has loads depending on what happens elsewhere in the script but several of them all reference a predefined value that determines how many times all the various loops should run.

This part of my script is navigating a file list within a program and copying the contents of a field and storing it as a variable. As the number of files will vary I've asked it to count the number of WAV files in folder that was previously captured in variable AF1.

Code: Select all

//Count Files in source directory for 1st file
CountFiles>AF1\*.wav,WavCount1,0
//Open Marker List
Press Alt
Send>8
Release Alt
Wait>1
MouseMoveRel>430,119
LClick
Wait>1
Press Home
//Copy Description of all tracks in first file
Let>loop=0
Repeat>loop
Press Tab *7
Press Ctrl
send>c
Release Ctrl
GetClipBoard>description1_%loop%
Wait>0.5
Press Tab
Press Down
Wait>0.5
Let>loop=loop+1
Until>loop=WavCount1
So lets say the number of Wav files in AF1 = 9

What should happen is that it copies the content of the field, stores it as variable descrption1_(with a number that increments for each loop), moves down the list to the next file and repeats. After 9 repeats it should stop.

What actually happens is that it appears to copy the content of the field, moves down to the next file and repeats but it never stops so that when it gets to the last file it just keeps copying that last file over and over again.

I don't understand why it's not stopping when it gets to 9

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: Looping Problem

Post by zabros2020 » Thu Sep 14, 2017 5:27 am

Hi RNIB,

This seems to work fine for me.
However, this bit of code CountFiles>AF1\*.wav,WavCount1,0 may be returning null for you.
You have no statements to cater for this when WavCount1 is 0.
If CountFiles returns 0, your loop will loop forever.

Also, make sure that AF1 is a valid directory and absolute path, e.g. C:\temp\tmp\
Loving MS's Capabilities!!!

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: Looping Problem

Post by zabros2020 » Thu Sep 14, 2017 7:03 am

something like:

Code: Select all

//Count Files in source directory for 1st file
CountFiles>AF1\*.wav,WavCount1,0
//Open Marker List
If>WavCount1>0
  Press Alt
  Send>8
  Release Alt
  Wait>1
  MouseMoveRel>430,119
  LClick
  Wait>1
  Press Home
  //Copy Description of all tracks in first file
  Let>loop=0
  Repeat>loop
    Press Tab *7
    Press Ctrl
    send>c
    Release Ctrl
    GetClipBoard>description1_%loop%
    Wait>0.5
    Press Tab
    Press Down
    Wait>0.5
    Let>loop=loop+1
  Until>loop=WavCount1
Else
  MessageModal>%WavCount1%
EndIf
Loving MS's Capabilities!!!

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