Sign in to follow this  
Followers 0
vidaLL

What is wrong with my Loop ....While/Wend

15 posts in this topic

 Hello all.

You are master in autoit maybe can tell me easily... Whats wrong with my Loop ?

HotKeySet("{ESC}", "Terminate")


#include <Excel.au3>
#include <IE.au3>
Global $sExcelFile = "C:\Users\e8760255\Desktop\Pasta1.xls" ; <== Add the name of the Excel file here and your User
Global $oExcel = _ExcelBookOpen($sExcelFile)
Global $aExcelData = _ExcelReadSheetToArray($oExcel);$oExcel
$oIE = _IECreate()
_IENavigate($oIE, "https://webhomolog.fazenda.sp.gov.br/simp"); https://webhomolog.fazenda.sp.gov.br/simp

;=======================>FROM HERE
While 1
$o_form = _IEFormGetObjByName($oIE, "form1")
$o_txtCpf = _IEFormElementGetObjByName($o_form, "txtCpf")
$o_txtNumDoc = _IEFormElementGetObjByName($o_form, "txtNumDoc")
$O_btnConsultar = _IEFormElementGetObjByName($o_form, "btnConsultar")

For $iRow = 1 To $aExcelData ; Process all read Excel rows
    _IEFormElementSetValue($o_txtCpf, $aExcelData[$iRow][1])
    _IEFormElementSetValue($o_txtNumDoc, $aExcelData[$iRow][2])
Next
$O_btnConsultar.click
_IELoadWait($oIE)

$o_form = _IEFormGetObjByName($oIE, "_ctl0")
$o_btnContinuar = _IEFormElementGetObjByName($o_form, "btnContinuar")
If IsObj($o_btnContinuar) Then
$o_btnContinuar.click
_IELoadWait($oIE)
EndIf


If not isObj($o_btnContinuar) Then
$o_form = _IEFormGetObjByName($oIE, "Form1")
$o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
$o_btnGare.click
_IELoadWait($oIE)
EndIf

$o_form = _IEFormGetObjByName($oIE, "Form1")
$o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
$o_btnGare.click
_IELoadWait($oIE)

; Doc informations
$o_form = _IEFormGetObjByName($oIE, "Form1")
$o_txtObs = _IEFormElementGetObjByName($o_form, "txtObs")
$o_txtDataPagto = _IEFormElementGetObjByName($o_form, "txtDataPagto")
$o_txtReceita = _IEFormElementGetObjByName($o_form, "txtReceita")


For $iRow = 1 To $aExcelData ; Process all read Excel rows
    _IEFormElementSetValue($o_txtObs, $aExcelData[$iRow][3])
    _IEFormElementSetValue($o_txtDataPagto, $aExcelData[$iRow][4])
    _IEFormElementSetValue($o_txtReceita, $aExcelData[$iRow][5])
Next
$o_form = _IEFormGetObjByName($oIE, "Form1")
$o_btnCalculoProd = _IEFormElementGetObjByName($o_form, "btnCalculoProd")
$o_btnCalculoProd.click
_IELoadWait($oIE)

$o_form = _IEFormGetObjByName($oIE, "Form1")
$o_btnGera = _IEFormElementGetObjByName($o_form, "btnGera")
$o_btnGera.click
_IELoadWait($oIE)

Sleep (6000)
Send("{CTRLDOWN}")
Send("{SHIFTDOWN}")
Send("s")
Send("{CTRLUP}")
Send("{SHIFTUP}")
Sleep (3000)
Send("{ALTDOWN}")
Send("s")
Send("{ALTUP}")
Sleep (1500)
Send("!{F4}")
Sleep (1500)

$o_form = _IEFormGetObjByName($oIE, "_ctl0");Form1
$o_btnSair = _IEFormElementGetObjByName ($o_form, "btnSair")
$o_btnSair.click

_ExcelRowDelete($oExcel,1)
;=======================>TO HERE
WEnd
Func Terminate()
    Exit 0
EndFunc

Appreciate your help.

Share this post


Link to post
Share on other sites



What do you mean by "wrong"? Do you get a syntax error when running the script? Doesn't the script do what you expect it to do?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What do you mean by "wrong"? Do you get a syntax error when running the script? Doesn't the script do what you expect it to do?

 

The script is doing what I want, however what happens ... I have an excel file with e.g 200 lines that serves as a database to put the information in IE ...However I do not know how to do to the script go to the second line excel at the end of the script I put him to delete the first line, so I can rotate in all remaining lines. It was here enters the Loop, can not I do.

 

Share this post


Link to post
Share on other sites

The content of the Excel sheet is already in the array. Process the array in the loop like this:

HotKeySet("{ESC}", "Terminate")


#include <Excel.au3>
#include <IE.au3>
Global $sExcelFile = "C:\Users\e8760255\Desktop\Pasta1.xls" ; <== Add the name of the Excel file here and your User
Global $oExcel = _ExcelBookOpen($sExcelFile)
Global $aExcelData = _ExcelReadSheetToArray($oExcel);$oExcel
$oIE = _IECreate()
_IENavigate($oIE, "https://webhomolog.fazenda.sp.gov.br/simp"); https://webhomolog.fazenda.sp.gov.br/simp

;=======================>FROM HERE
For $iRow = 1 To $aExcelData[0][0]
    $o_form = _IEFormGetObjByName($oIE, "form1")
    $o_txtCpf = _IEFormElementGetObjByName($o_form, "txtCpf")
    $o_txtNumDoc = _IEFormElementGetObjByName($o_form, "txtNumDoc")
    $O_btnConsultar = _IEFormElementGetObjByName($o_form, "btnConsultar")

    _IEFormElementSetValue($o_txtCpf, $aExcelData[$iRow][1])
    _IEFormElementSetValue($o_txtNumDoc, $aExcelData[$iRow][2])
    $O_btnConsultar.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "_ctl0")
    $o_btnContinuar = _IEFormElementGetObjByName($o_form, "btnContinuar")
    If IsObj($o_btnContinuar) Then
        $o_btnContinuar.click
        _IELoadWait($oIE)
    EndIf

    If Not IsObj($o_btnContinuar) Then
        $o_form = _IEFormGetObjByName($oIE, "Form1")
        $o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
        $o_btnGare.click
        _IELoadWait($oIE)
    EndIf

    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
    $o_btnGare.click
    _IELoadWait($oIE)

    ; Doc informations
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_txtObs = _IEFormElementGetObjByName($o_form, "txtObs")
    $o_txtDataPagto = _IEFormElementGetObjByName($o_form, "txtDataPagto")
    $o_txtReceita = _IEFormElementGetObjByName($o_form, "txtReceita")

    _IEFormElementSetValue($o_txtObs, $aExcelData[$iRow][3])
    _IEFormElementSetValue($o_txtDataPagto, $aExcelData[$iRow][4])
    _IEFormElementSetValue($o_txtReceita, $aExcelData[$iRow][5])
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnCalculoProd = _IEFormElementGetObjByName($o_form, "btnCalculoProd")
    $o_btnCalculoProd.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnGera = _IEFormElementGetObjByName($o_form, "btnGera")
    $o_btnGera.click
    _IELoadWait($oIE)

    Sleep(6000)
    Send("{CTRLDOWN}")
    Send("{SHIFTDOWN}")
    Send("s")
    Send("{CTRLUP}")
    Send("{SHIFTUP}")
    Sleep(3000)
    Send("{ALTDOWN}")
    Send("s")
    Send("{ALTUP}")
    Sleep(1500)
    Send("!{F4}")
    Sleep(1500)

    $o_form = _IEFormGetObjByName($oIE, "_ctl0");Form1
    $o_btnSair = _IEFormElementGetObjByName($o_form, "btnSair")
    $o_btnSair.click

Next

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

 

The content of the Excel sheet is already in the array. Process the array in the loop like this:

HotKeySet("{ESC}", "Terminate")


#include <Excel.au3>
#include <IE.au3>
Global $sExcelFile = "C:\Users\e8760255\Desktop\Pasta1.xls" ; <== Add the name of the Excel file here and your User
Global $oExcel = _ExcelBookOpen($sExcelFile)
Global $aExcelData = _ExcelReadSheetToArray($oExcel);$oExcel
$oIE = _IECreate()
_IENavigate($oIE, "https://webhomolog.fazenda.sp.gov.br/simp"); https://webhomolog.fazenda.sp.gov.br/simp

;=======================>FROM HERE
For $iRow = 1 To $aExcelData[0][0]
    $o_form = _IEFormGetObjByName($oIE, "form1")
    $o_txtCpf = _IEFormElementGetObjByName($o_form, "txtCpf")
    $o_txtNumDoc = _IEFormElementGetObjByName($o_form, "txtNumDoc")
    $O_btnConsultar = _IEFormElementGetObjByName($o_form, "btnConsultar")

    _IEFormElementSetValue($o_txtCpf, $aExcelData[$iRow][1])
    _IEFormElementSetValue($o_txtNumDoc, $aExcelData[$iRow][2])
    $O_btnConsultar.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "_ctl0")
    $o_btnContinuar = _IEFormElementGetObjByName($o_form, "btnContinuar")
    If IsObj($o_btnContinuar) Then
        $o_btnContinuar.click
        _IELoadWait($oIE)
    EndIf

    If Not IsObj($o_btnContinuar) Then
        $o_form = _IEFormGetObjByName($oIE, "Form1")
        $o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
        $o_btnGare.click
        _IELoadWait($oIE)
    EndIf

    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
    $o_btnGare.click
    _IELoadWait($oIE)

    ; Doc informations
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_txtObs = _IEFormElementGetObjByName($o_form, "txtObs")
    $o_txtDataPagto = _IEFormElementGetObjByName($o_form, "txtDataPagto")
    $o_txtReceita = _IEFormElementGetObjByName($o_form, "txtReceita")

    _IEFormElementSetValue($o_txtObs, $aExcelData[$iRow][3])
    _IEFormElementSetValue($o_txtDataPagto, $aExcelData[$iRow][4])
    _IEFormElementSetValue($o_txtReceita, $aExcelData[$iRow][5])
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnCalculoProd = _IEFormElementGetObjByName($o_form, "btnCalculoProd")
    $o_btnCalculoProd.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnGera = _IEFormElementGetObjByName($o_form, "btnGera")
    $o_btnGera.click
    _IELoadWait($oIE)

    Sleep(6000)
    Send("{CTRLDOWN}")
    Send("{SHIFTDOWN}")
    Send("s")
    Send("{CTRLUP}")
    Send("{SHIFTUP}")
    Sleep(3000)
    Send("{ALTDOWN}")
    Send("s")
    Send("{ALTUP}")
    Sleep(1500)
    Send("!{F4}")
    Sleep(1500)

    $o_form = _IEFormGetObjByName($oIE, "_ctl0");Form1
    $o_btnSair = _IEFormElementGetObjByName($o_form, "btnSair")
    $o_btnSair.click

Next

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

 

I tried it too... no sucess...

If it is not asking too much but already asking, just try running the files I posted ...

Pasta1.xls

WATER.au3

Share this post


Link to post
Share on other sites

Sorry, but I don't have the time to test it for you. Just a few seconds to post a few questions.

If you run my version of the script do you get any error messages written to the Scite console?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No... Its runs normally but its not reading all lines of .xls

it runs just once then stop. Weird :ermm:

Share this post


Link to post
Share on other sites

The loop runs 2 times for me. But I get a lot of errors because I don't do the clicks.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sorry.. just correcting my previous message : is not transcribing  the read information from next line.

Share this post


Link to post
Share on other sites

Can you add a _IELoadWait at the end of the loop and try again?

    $o_form = _IEFormGetObjByName($oIE, "_ctl0");Form1
    $o_btnSair = _IEFormElementGetObjByName($o_form, "btnSair")
    $o_btnSair.click
    _IELoadWait($oIE) ; <== Add this
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Im your Fan man... Thanks very much

Works like a charm .

Share this post


Link to post
Share on other sites

Glad we could solve this problem :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

water, a simples question : is there a way to use a Object from a webpage to "save target as" ?

Share this post


Link to post
Share on other sites

Don't know. But I remember there was a thread regarding this subject just a few days ago. So if you search the forum for "save target as" ...


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  
Followers 0