Jump to content
Sign in to follow this  
kctvt

Should use For Next or Do Until or Something ?

Recommended Posts

kctvt

Should use For Next or Do Until or Something.

Yah, this's my question today. I got a problem and ... I think I need help.

This's my code now :

#include <IE.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#Include <Excel.au3>
#include <Word.au3>


$part = @ScriptDir&"\Care.xls"

$oExcel = _ExcelBookOpen($part)
Sleep(1000)



Run ("Notepad.exe")
WinWaitActive("Untitled - Notepad")
ControlSend("[CLASS:Notepad]", "", "Edit1", "Hello, this is the first line)
Sleep(500)
Send("{ENTER}")
Sleep(500)



Do

$i = 6

$Name = _ExcelReadCell($oExcel,$i,1)
$Age = _ExcelReadCell($oExcel,$i,1)
$Sex = _ExcelReadCell($oExcel,$i,3)

$Info = ("===============" & @CR & $Name & $Age & $Sex & "==================" & @CR")


IF _ExcelReadCell($oExcel,$i,4) = "" then
ControlSend("[CLASS:Notepad]", "", "Edit1", $Info)
Sleep(500)
EndIf

$i = $i + 1

Until _ExcelReadCell($oExcel,$i,1) = ""

---> Problem is : $i dont change from 6 to 7, 7 to 8, 8 to 9, 9 to 10. $i still 6, not change.

And this's my Excel file :

1       |2       |3         |4
----------------------------------
Peter   |25      |Male      |
Tom     |26      |Male      |
Mary    |30      |Female    |Save 
Daisy   |19      |Female    |

I want the code read Excel file, then If NUMBER 4 dont write "Save" , the code'll take value from that Row and paste to Notepad.

They'll take the value of all Row until NUMBER 1 = ""

--> I want to do that. But @_@ I dont know how.

Edited by kctvt

Share this post


Link to post
Share on other sites
hannes08

Hi kctvt,

what you coded here is an infinite loop, as you always set $i = 6 on the beginning of every loop.

Consider changing it to "$i = 1" before beginning the loop and at the end of the loop to "$i += 1" to iterate.

Regards,

Hannes


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
kctvt

ok. THanks Hannes. This code works :)

#include <IE.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#Include <Excel.au3>
#include <Word.au3>


$part = @ScriptDir&"\Care.xls"

$oExcel = _ExcelBookOpen($part)
Sleep(1000)



Run ("Notepad.exe")
WinWaitActive("Untitled - Notepad")
ControlSend("[CLASS:Notepad]", "", "Edit1", "Hello, this is the first line)
Sleep(500)
Send("{ENTER}")
Sleep(500)

$i = 6

Do

$Name = _ExcelReadCell($oExcel,$i,1)
$Age = _ExcelReadCell($oExcel,$i,1)
$Sex = _ExcelReadCell($oExcel,$i,3)

$Info = ("===============" & @CR & $Name & $Age & $Sex & "==================" & @CR")


IF _ExcelReadCell($oExcel,$i,4) = "" then
ControlSend("[CLASS:Notepad]", "", "Edit1", $Info)
Sleep(500)
EndIf

$i += 1   ;;;;;;;  NOT $i = $i + 1

Until _ExcelReadCell($oExcel,$i,1) = ""
Edited by kctvt

Share this post


Link to post
Share on other sites
hannes08

Hey kctvt,

just a short sidenote:

$i += 1 is the same as $i = $i + 1

Regards,

Hannes


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.