Jump to content
youtuber

Progress Problem While Receiving Data

Recommended Posts

youtuber

Hi, progress is not working while receiving data
What should I do to progress step by step in the Progress?

#include <String.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

$sList = "https://www.autoitscript.com/forum/topic/34658-are-my-autoit-exes-really-infected/" & @crlf & _
"https://www.autoitscript.com/forum/topic/148023-amending-the-faq-in-the-help-file/"

$Form1 = GUICreate("Form1", 314, 424, 327, 136)
$Edit1 = GUICtrlCreateEdit("", 16, 40, 281, 313)
GUICtrlSetData($Edit1, $sList)
$CheckData = GUICtrlCreateButton("Check Data", 16, 376, 107, 25)
GUICtrlSetState($CheckData,$GUI_FOCUS)
$Progress1 = GUICtrlCreateProgress(152, 376, 142, 25)

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $CheckData
            GUICtrlSetData($progress1, "")
            Local $aEditread = StringSplit(GUICtrlRead($Edit1), @CRLF, 1)

            Local $aData, $string ,$progress

            For $i = 1 To $aEditread[0]
                $string = Connections($aEditread[$i])
                $progress = 100 / $string
                GUICtrlSetData($progress1, $progress * $i)
                If @error Then
                    ExitLoop
                EndIf

                $string = StringRegExpReplace($string, '(?s)[\n\r\t\v]', '')
                $string = StringStripWS($string, 7)
                $aData = _StringBetween($string, 'lightboxedImages">', '</div>')

                For $j = 0 To UBound($aData) - 1
                    ConsoleWrite($aData[$j] & @CRLF)
                Next
            Next
EndSwitch
WEnd

Func Connections($address)
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $address, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept", "*/*")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.Send()
    If @error Then
        ConsoleWrite("Error connection")
        $oHTTP = 0
        Return SetError(1)
    EndIf

    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf
    $oHTTP = Null
    Return -1
EndFunc

 

Share this post


Link to post
Share on other sites
youtuber

I think it's actually

I am not sure

Case $CheckData
            GUICtrlSetData($progress1, "")
            Local $aEditread = StringSplit(GUICtrlRead($Edit1), @CRLF, 1)

            Local $aData, $string ,$progress

            For $i = 1 To $aEditread[0]
                $string = Connections($aEditread[$i])
                $progress = $i / $string
                GUICtrlSetData($progress1, $progress * $i)
                If @error Then
                    ExitLoop
                EndIf

                $string = StringRegExpReplace($string, '(?s)[\n\r\t\v]', '')
                $string = StringStripWS($string, 7)
                $aData = _StringBetween($string, 'lightboxedImages">', '</div>')

                For $j = 0 To UBound($aData) - 1
                    ConsoleWrite($aData[$j] & @CRLF)
                Next
            Next
            GUICtrlSetData($progress1, 100)
EndSwitch

 

Share this post


Link to post
Share on other sites
kylomas

youtuber,

If you are trying to determine the progress of entries read from the edit control then try this...

#include <String.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>

$sList = "https://www.autoitscript.com/forum/topic/34658-are-my-autoit-exes-really-infected/" & @crlf & _
"https://www.autoitscript.com/forum/topic/148023-amending-the-faq-in-the-help-file/"

$Form1 = GUICreate("Form1", 314, 424, 327, 136)
$Edit1 = GUICtrlCreateEdit("", 16, 40, 281, 313)
GUICtrlSetData($Edit1, $sList)
$CheckData = GUICtrlCreateButton("Check Data", 16, 376, 107, 25)
GUICtrlSetState($CheckData,$GUI_FOCUS)
$Progress1 = GUICtrlCreateProgress(152, 376, 142, 25)

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $CheckData
            GUICtrlSetData($progress1, "")
            Local $aEditread = StringSplit(GUICtrlRead($Edit1), @CRLF, 1)

            Local $aData, $string ,$progress

            For $i = 1 To $aEditread[0]
                $string = Connections($aEditread[$i])
                $progress = ($i / $aEditread[0]) * 100      ; (partial / total) * 100
                GUICtrlSetData($progress1, $progress)
                If @error Then
                    ExitLoop
                EndIf

                $string = StringRegExpReplace($string, '(?s)[\n\r\t\v]', '')
                $string = StringStripWS($string, 7)
                $aData = _StringBetween($string, 'lightboxedImages">', '</div>')

                For $j = 0 To UBound($aData) - 1
                    ConsoleWrite($aData[$j] & @CRLF)
                Next
            Next
EndSwitch
WEnd

Func Connections($address)
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $address, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0")
    $oHTTP.SetRequestHeader("Accept", "*/*")
    $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3")
    $oHTTP.Send()
    If @error Then
        ConsoleWrite("Error connection")
        $oHTTP = 0
        Return SetError(1)
    EndIf

    If $oHTTP.Status = 200 Then
        Local $sReceived = $oHTTP.ResponseText
        $oHTTP = Null
        Return $sReceived
    EndIf
    $oHTTP = Null
    Return -1
EndFunc

kylomas

  • Like 1

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
ripdad

youtuber,

You have to move @error statement for Connections().

Otherwise, it's not very useful where it is.

Like this...

For $i = 1 To $aEditread[0]
    $string = Connections($aEditread[$i])
    If @error Then
        ExitLoop
    EndIf

 

  • Like 1

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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

×

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.