Jump to content

While Loop to change numbers on a file name


Recommended Posts

Hei.... I have a whole list of bitmap files to load one by one into a program that prints this bitmap file for me and pauses for an appropriate amount of time. The file numbers range from 000001-000147. Instead of having 3 while loops (one for 0-9,one for 10-99 and one for 100-147) and changing the number of leading zeroes, is there a way that I could have AutoIt count the numbers from 001-147? Like 001,002,003...099,100,...147? That way I would only need one whle loop. Below I have posted the code.

Thanks. :)

$time=1000

$i= 0

While $i<= 9

Send("^o")

WinWaitActive("Open")

$filename= "C:\3d-printing\Printer-calibration\Phantoms\scaling_phantom-4mil-00000"& $i &".bmp"

Send($filename,1)

;; Click on open:

ControlClick("Open", "", "[CLASSNN:Button2]")

$i=$i+ 1

Sleep($time)

;WinMenuSelectItem("COM1-scaling_phantom-4mil-00000"& $i &".bmp","","& File")

;

WEnd

$time=100

$i= 10

While $i<= 99

Send("^o")

WinWaitActive("Open")

$filename= "C:\3d-printing\Printer-calibration\Phantoms\scaling_phantom-4mil-0000"& $i &".bmp"

Send($filename,1)

;; Click on open:

ControlClick("Open", "", "[CLASSNN:Button2]")

$i=$i+ 1

Sleep($time)

;WinMenuSelectItem("COM1-scaling_phantom-4mil-00000"& $i &".bmp","","& File")

;

WEnd

$time=100

$i= 100

While $i<= 147

Send("^o")

WinWaitActive("Open")

$filename= "C:\3d-printing\Printer-calibration\Phantoms\scaling_phantom-4mil-000"& $i &".bmp"

Send($filename,1)

;; Click on open:

ControlClick("Open", "", "[CLASSNN:Button2]")

$i=$i+ 1

Sleep($time)

;WinMenuSelectItem("COM1-scaling_phantom-4mil-00000"& $i &".bmp","","& File")

;

WEnd

Link to comment
Share on other sites

$length = 4

For $x = 1 to 147
    $num = $x
    While StringLen($num) < $length
        $num = "0" & $num
    WEnd
    msgbox(0,"",$num)
Next

Obviously you'll want to remove the msgbox, but that's just to show you the output.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...