Jump to content

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


Go to solution Solved by water,

Recommended Posts

 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.

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Glad we could solve this problem :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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