Jump to content

Trying to end a While...Wend loop


mapoul
 Share

Recommended Posts

My non-programming brain has been trying for the past couple of days to figure out the logic to end a loop that I've created. I've searched the forums and help files for ideas, but I haven't found anything that has worked for me yet.

Here's the summary: I'm trying to copy text from Excel, move down one cell, copy that cell, etc. until I reach a blank (null) cell. So I tried to tell the loop to only run when StringLen(ClipGet) > 4 (all of my text strings are 10 or more, null cells appear to = 2). However, the loop doesn't stop once it copies the null cell, it just keeps going forever. I'm sure it's something simple that I just don't understand or a flaw in my logic, but I can't seem to figure it out.

Any help is greatly appreciated.

CODE
HotKeySet("{ESC}", "MyExit")

ShellExecute("Book1.xls","","C:\","open")

WinActivate("Microsoft Excel - Book1.xls","")

WinWaitActive("Microsoft Excel - Book1.xls","", 2)

Global $clip=ClipGet()

Global $len=StringLen($clip)

Send("^c")

While $len > 4

Sleep(1000)

Send("^c")

Sleep(1000)

Send("{DOWN}")

WEnd

MsgBox(4096, "Done?", "Yes")

Func MyExit()

Exit

EndFunc

BTW, the Excel file just has company names in it:

Cell A1=Continuous Computing

Cell A2=Alcatel USA

Cell A3=Nortel Networks

Cell A4=blank (null)

Thank you,

mapoul

Link to comment
Share on other sites

The code doesn't seem to have a way to redeclare the $lens variable. Since the $lens isn't being redeclared, it stays as less than 4 and your loop continues.

Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

  • Moderators

As BALA Stated:

While $len > 4
    Sleep(1000)
    Send("^c")
    Sleep(1000)
    Send("{DOWN}")
    $len = StringLen(ClipGet())
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well heres some

$holder will now contain all whats clipped with a ; to seperate

HotKeySet("{ESC}", "MyExit")
ShellExecute("Book1.xls","","C:\","open")
WinActivate("Microsoft Excel - Book1.xls","")
WinWaitActive("Microsoft Excel - Book1.xls","", 2)

Global $clip
Global $len = 10
Global $holder = ""

While $len > 4
    Sleep(1000)
    Send("^c")
    Sleep(1000)
    Send("{DOWN}")
    $clip=ClipGet()
    $holder = $holder & ";" & $clip
    $len=StringLen($clip)
WEnd
MsgBox(0,0,$holder)
MsgBox(4096, "Done?", "Yes")

Func MyExit() 
 Exit
EndFunc

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

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...