Jump to content

$count -1 not working and stop button


 Share

Go to solution Solved by water,

Recommended Posts

Hello.. Here i have this code. Like title says, $count -1 not updating and how i can make exit button to work while code is running, It works after code is done

Func _Scraping()
Global $oIE = _IECreate("", 0, 0)
Local $Count = $i
For $i = 1 to _FileCountLines($file)
$line = FileReadLine($file, $i)

$Count -1
_IE()
_CSV()
Sleep (500)
Next
_CloseIE()
MsgBox(0, "", "Done")
GUICtrlSetData($txt, "")
EndFunc

Func _IE()
$Count -1
_IENavigate($oIE, $line)
_IELoadWait($oIE, 2000)
$HTML = _IEBodyReadHTML($oIE)
$result = _StringBetween($HTML, $PriceDivR, '</span')
Global $result2 = $result[1]
$result3 = _StringBetween($HTML, $StockDivR, '</span')
Global $result4 = $result3[1]

GUICtrlSetData($txt, $result2 & "  " & $result4 & "    " &  $Line &  "  "  & $Count & " URL done")
EndFunc

 

Edited by dersiniar
Link to comment
Share on other sites

  • dersiniar changed the title to $count -1 not working and stop button
  • Solution

I think this should be: 

$Count -= 1 ; equal to $Count = $Count - 1

 

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

Hi @dersiniar,

what are you try to achieve? Your posted code is very incomplete and we have to do assumptions.

#include-once
#include <File.au3>
#include <IE.au3>
#include <String.au3>

Global $Count, $file, $line, $txt, $PriceDivR, $StockDivR

Func _Scraping()
    Global $oIE = _IECreate("", 0, 0)
    For $i = 1 To _FileCountLines($file)
        $line = FileReadLine($file, $i)

        $Count -= 1 ; decrease the count by one
        _IE()
        ;~ _CSV()
        Sleep(500)
    Next
    ;~ _CloseIE()
    MsgBox(0, "", "Done")
    GUICtrlSetData($txt, "")
EndFunc   ;==>_Scraping

Func _IE()
    $Count -= 1 ; do you want to decrease the count here too?
    _IENavigate($oIE, $line)
    _IELoadWait($oIE, 2000)
    $HTML = _IEBodyReadHTML($oIE)
    $result = _StringBetween($HTML, $PriceDivR, '</span')
    Global $result2 = $result[1]
    $result3 = _StringBetween($HTML, $StockDivR, '</span')
    Global $result4 = $result3[1]

    GUICtrlSetData($txt, $result2 & "  " & $result4 & "    " & $line & "  " & $Count & " URL done")
EndFunc   ;==>_IE

Like @water already said: $Count -= 1 do the job, but the rest of the logic wouldn't properly work.

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

2 minutes ago, SOLVE-SMART said:

Hi @dersiniar,

what are you try to achieve? Your posted code is very incomplete and we have to do assumptions.

#include-once
#include <File.au3>
#include <IE.au3>
#include <String.au3>

Global $Count, $file, $line, $txt, $PriceDivR, $StockDivR

Func _Scraping()
    Global $oIE = _IECreate("", 0, 0)
    For $i = 1 To _FileCountLines($file)
        $line = FileReadLine($file, $i)

        $Count -= 1 ; decrease the count by one
        _IE()
        ;~ _CSV()
        Sleep(500)
    Next
    ;~ _CloseIE()
    MsgBox(0, "", "Done")
    GUICtrlSetData($txt, "")
EndFunc   ;==>_Scraping

Func _IE()
    $Count -= 1 ; do you want to decrease the count here too?
    _IENavigate($oIE, $line)
    _IELoadWait($oIE, 2000)
    $HTML = _IEBodyReadHTML($oIE)
    $result = _StringBetween($HTML, $PriceDivR, '</span')
    Global $result2 = $result[1]
    $result3 = _StringBetween($HTML, $StockDivR, '</span')
    Global $result4 = $result3[1]

    GUICtrlSetData($txt, $result2 & "  " & $result4 & "    " & $line & "  " & $Count & " URL done")
EndFunc   ;==>_IE

Like @water already said: $Count -= 1 do the job, but the rest of the logic wouldn't properly work.

Best regards
Sven

________________
Stay innovative!

Everything else works like charm, its just a tiny part of full code. And i got count to work thanks @water

Edited by dersiniar
Link to comment
Share on other sites

Hi again,

Quote

Everything else works like charm

If you think so, okay 😁 .

#include-once
#include <File.au3>
#include <IE.au3>
#include <String.au3>

HotKeySet('{F10}', '_exit')

Global $Count, $file, $line, $txt, $PriceDivR, $StockDivR

Func _Scraping()
    Global $oIE = _IECreate("", 0, 0)
    For $i = 1 To _FileCountLines($file)
        $line = FileReadLine($file, $i)

        $Count -= 1 ; decrease the count by one
        _IE()
        ;~ _CSV()
        Sleep(500)
    Next
    ;~ _CloseIE()
    MsgBox(0, "", "Done")
    GUICtrlSetData($txt, "")
EndFunc   ;==>_Scraping

Func _IE()
    $Count -= 1 ; do you want to decrease the count here too?
    _IENavigate($oIE, $line)
    _IELoadWait($oIE, 2000)
    $HTML = _IEBodyReadHTML($oIE)
    $result = _StringBetween($HTML, $PriceDivR, '</span')
    Global $result2 = $result[1]
    $result3 = _StringBetween($HTML, $StockDivR, '</span')
    Global $result4 = $result3[1]

    GUICtrlSetData($txt, $result2 & "  " & $result4 & "    " & $line & "  " & $Count & " URL done")
EndFunc   ;==>_IE

Func _exit()
    Exit
EndFunc

One suggestion is to use HotKeySet. In the example code I added this function (_exit).

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Just now, SOLVE-SMART said:

Hi again,

#include-once
#include <File.au3>
#include <IE.au3>
#include <String.au3>

HotKeySet('{F10}', '_exit')

Global $Count, $file, $line, $txt, $PriceDivR, $StockDivR

Func _Scraping()
    Global $oIE = _IECreate("", 0, 0)
    For $i = 1 To _FileCountLines($file)
        $line = FileReadLine($file, $i)

        $Count -= 1 ; decrease the count by one
        _IE()
        ;~ _CSV()
        Sleep(500)
    Next
    ;~ _CloseIE()
    MsgBox(0, "", "Done")
    GUICtrlSetData($txt, "")
EndFunc   ;==>_Scraping

Func _IE()
    $Count -= 1 ; do you want to decrease the count here too?
    _IENavigate($oIE, $line)
    _IELoadWait($oIE, 2000)
    $HTML = _IEBodyReadHTML($oIE)
    $result = _StringBetween($HTML, $PriceDivR, '</span')
    Global $result2 = $result[1]
    $result3 = _StringBetween($HTML, $StockDivR, '</span')
    Global $result4 = $result3[1]

    GUICtrlSetData($txt, $result2 & "  " & $result4 & "    " & $line & "  " & $Count & " URL done")
EndFunc   ;==>_IE

Func _exit()
    Exit
EndFunc

If you think so, okay 😁 .

One suggestion is to use HotKeySet. In the example code I added this function (_exit).

Best regards
Sven

________________
Stay innovative!

No need to think so :D i have tested it like 200+ times lol 

Cant make the button to work?
 

$SimpleGUI = GUICreate("", 300, 220, -1, -1, $WS_BORDER)
WinSetTrans($SimpleGUI, "", 250)
GUISetBkColor(0x000000)
Global $Text = GUICtrlCreateLabel("Scraper", 10, 12, 290, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetFont(-1, 16)
GUICtrlCreateLabel("Made by dersiniar@gmail.com", 10, 40, 280, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetFont(-1, 12)
GUICtrlCreateLabel ("", 10,40,280,3, $SS_SUNKEN)
$ImportButton = GUICtrlCreateButton("ADD URLs", 18, 70, 125, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetBkColor(-1, 0x545454)
$Settings = GUICtrlCreateButton("Settings", 45, 100, 70, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetBkColor(-1, 0x545454)
$ExitButton = GUICtrlCreateButton("Exit", 180, 100, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetBkColor(-1, 0x545454)
$UpdatetButton = GUICtrlCreateButton("Update", 158, 70, 125, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xb8b8b8)
GUICtrlSetBkColor(-1, 0x545454)
GUISetState(@SW_Show)

 

Link to comment
Share on other sites

Hi @dersiniar,

without more code, especially your while loop for the GUI event handling, it's just guessing.
So please share a bit more 😉 .

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Hotkey reacts much faster. As described in the help file "A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function"

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

BTW: When you want to reply to a post, please simply add the text at the end of the thread. Do not use the Quote button as this only clutters the thread.
We all know what we have posted before 😉 

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