Jump to content

"collect" data inside the <tr> </tr> tags


Valnurat
 Share

Recommended Posts

Modified @Nine's code a little, not the most elegant I guess. Maybe you can change the inputbox with a checkbox? I don't have the time to find out myself atm, sorry :)

Just enter anything in inputbox and it will stop at the end of current iteration. And button will change to "Resume". Click on resume to continue from where left off.

Can't say anything for the repeat timer atm, maybe another loop, with say 10 seconds sleeps where you continue to add up until 45 minutes and then exit loop, run start. May also use the input box to prematurely end that timer.

#include <Array.au3>
#include <IE.au3>
;#include "WinHttp.au3"
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
    , ["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
    , ["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:", 10, 10)
$idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:", 10, 52)
$idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:", 10, 95)
Local $idDate = GUICtrlCreateDate("", 10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

$idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

Local $idInput_Test = GUICtrlCreateInput("",150,260,100,25)

GUICtrlCreateLabel("Time to rerun", 10, 180)
GUICtrlCreateInput("45", 10, 230, 30, 20)
Local $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
  _Fill_List()
EndIf

Local $state = 0, $indx= 0

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Local $sFill = ""
      For $i = 0 To _GUICtrlListBox_GetCount($idMylist) - 1
        $sFill &= _GUICtrlListBox_GetText($idMylist, $i) & "|"
      Next
      $sFill = StringTrimRight($sFill, 1)
      _ArrayAdd($aTmpRejser, $sFill)
      _FileWriteFromArray($Rejserspath, $aTmpRejser)
      ExitLoop
    Case $idButton_AddTrip
      $sOrigin = GUICtrlRead($idComboFra)
      $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
      $sDest = GUICtrlRead($idComboTil)
      $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
      _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
      ;       Case $idButton_Clear
      ;           GUICtrlSetData($idMylist, "")
    Case $idButton_Run
      If $state Then
        $state = 0
        $indx = 0
        GUICtrlSetData($idButton_Run, "Start")
        ;ExitLoop
      Else
        $state = 1
        ;$indx = 0
        GUICtrlSetData($idButton_Run, "Stop")
      EndIf
  EndSwitch
  If $state Then
    ;ConsoleWrite ("started" & @CRLF)
    If $indx < _GUICtrlListBox_GetCount($idMylist) Then
      $RDMSleep = Random(5, 9, 1)
      $RDMSleep = $RDMSleep * 1000
      Sleep($RDMSleep)
      ConsoleWrite(_GUICtrlListBox_GetText($idMylist, $indx) & @CRLF)
      $indx += 1

    if GUICtrlRead($idInput_Test) <> "" then
        $state = 0
        GUICtrlSetData($idInput_Test,"")
        GUICtrlSetData($idButton_Run, "Resume")
      EndIf
    Else
      $state = 0
      $indx = 0
      GUICtrlSetData($idButton_Run, "Start")
    EndIf
  EndIf

WEnd

Func _Fill_List()
  ; Read the file into an array
  Local $array
  _FileReadToArray($Rejserspath, $array)
  ; Check we read something
  If IsArray($array) Then
    ; Convert to a string with delimiters
    $sList = ""
    For $i = 1 To $array[0]
      $sList &= "|" & $array[$i]
    Next
    ; And fill the list
    GUICtrlSetData($idMylist, $sList)
  EndIf

EndFunc   ;==>_Fill_List

 

Edited by GokAy
Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

19 minutes ago, Nine said:

Here one way how to remove the Sleep and make it work :

#include <Array.au3>
#include <IE.au3>
;#include "WinHttp.au3"
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
    , ["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
    , ["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:", 10, 10)
$idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:", 10, 52)
$idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:", 10, 95)
Local $idDate = GUICtrlCreateDate("", 10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

$idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

GUICtrlCreateLabel("Time to rerun", 10, 180)
GUICtrlCreateInput("45", 10, 230, 30, 20)
Local $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
  _Fill_List()
EndIf

Local $state, $indx, $cal

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Local $sFill = ""
      For $i = 0 To _GUICtrlListBox_GetCount($idMylist) - 1
        $sFill &= _GUICtrlListBox_GetText($idMylist, $i) & "|"
      Next
      $sFill = StringTrimRight($sFill, 1)
      _ArrayAdd($aTmpRejser, $sFill)
      _FileWriteFromArray($Rejserspath, $aTmpRejser)
      ExitLoop
    Case $idButton_AddTrip
      $sOrigin = GUICtrlRead($idComboFra)
      $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
      $sDest = GUICtrlRead($idComboTil)
      $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
      _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
      ;       Case $idButton_Clear
      ;           GUICtrlSetData($idMylist, "")
    Case $idButton_Run
      If $state Then
        $state = 0
        GUICtrlSetData($idButton_Run, "Start")
      Else
        $state = 1
        $indx = 0
        $cal = 0
        GUICtrlSetData($idButton_Run, "Stop")
      EndIf
  EndSwitch
  If $state Then
    If $indx < _GUICtrlListBox_GetCount($idMylist) Then
      If Not $cal Then
        $RDMSleep = Random(2, 4, 1) * 1000
        $hTimer = TimerInit()
        $cal = 1
      ElseIf TimerDiff($hTimer) > $RDMSleep Then
        ConsoleWrite(_GUICtrlListBox_GetText($idMylist, $indx) & @CRLF)
        $indx += 1
        $cal = 0
      EndIf
    Else
      $state = 0
      GUICtrlSetData($idButton_Run, "Start")
    EndIf
  EndIf

WEnd

Func _Fill_List()
  ; Read the file into an array
  Local $array
  _FileReadToArray($Rejserspath, $array)
  ; Check we read something
  If IsArray($array) Then
    ; Convert to a string with delimiters
    $sList = ""
    For $i = 1 To $array[0]
      $sList &= "|" & $array[$i]
    Next
    ; And fill the list
    GUICtrlSetData($idMylist, $sList)
  EndIf

EndFunc   ;==>_Fill_List

 

I don't know what to say.

👍😲😶

Do you think, you can help me with last thing about the timer that re-run for..next a specific time? 🙏

Yours sincerely

Kenneth.

Link to comment
Share on other sites

2 minutes ago, Valnurat said:

Do you think, you can help me with last thing about the timer that re-run for..next a specific time?

I do not understand what you mean.  Please explain more explicitly what is your issue.

Link to comment
Share on other sites

When you say For...Next, you now mean my pseudo-loop, right ?  And you want to start my pseudo-loop after the number (e.g. 45) of minutes inside the input box ?  What would happen if the user change the input box in the middle of the period (I would assume the counter should be reset) ?  When it is restarted automatically, I presume the button should be change from Start to Stop, right ?  When the pseudo-loop is manually started, I would assume that the counter would be reset also, right ? Is there some more details you would like to share ?

Edited by Nine
Link to comment
Share on other sites

16 minutes ago, Valnurat said:

I will disable input so it is not possible to add any thing before I press the Stop button.

Good idea.  After looking at the code, you could simply use AdLibRegister/AdlibUnRegister to enable and disable the timer.  And the AdLib function would simply set $State = 1 and the other required parameters.  Not very complicated.  Try it, if you have trouble with it, post the code that is not working.

Link to comment
Share on other sites

I feel I got it in some point, but I can't stop the countdown for the next run when I press the Stop button.

#include <Array.au3>
#include <IE.au3>
#include <WinHttp.au3>
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
                    ,["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
                    ,["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:",10,10)
$idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) -1
    $sFill &= $aBase[$i][0] & "|" ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:",10,52)
$idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) -1
    $sFill &= $aBase[$i][0] & "|" ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:",10,95)
Local $idDate = GUICtrlCreateDate("" ,10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

$idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

GUICtrlCreateLabel("Time to rerun",10,180)
Global $tReRunTimer = GUICtrlCreateInput("1", 10, 230, 30, 20)
Local $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
    _Fill_List()
EndIf

Local $state, $indx, $cal, $RDMSleep, $hTimer

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Local $sFill = ""
            For $i = 0 to _GUICtrlListBox_GetCount($idMylist) -1
                $sFill &= _GUICtrlListBox_GetText($idMylist,$i) & "|"
            Next
            $sFill = StringTrimRight($sFill, 1)
            _ArrayAdd($aTmpRejser, $sFill)
            _FileWriteFromArray($Rejserspath, $aTmpRejser)
            ExitLoop
        Case $idButton_AddTrip
            $sOrigin = GUICtrlRead($idComboFra)
            $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
            $sDest = GUICtrlRead($idComboTil)
            $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
            _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
;       Case $idButton_Clear
;           GUICtrlSetData($idMylist, "")
        Case $idButton_Run
            If $state Then
                $state = 0
                GUICtrlSetData($idButton_Run, "Start")
                MsgBox(0,$state,"Start")
;               ExitLoop
            Else
                $state = 1
                $indx = 0
                GUICtrlSetData($idButton_Run, "Stop")
                MsgBox(0,$state,"Stop" & $indx)
            EndIf
    EndSwitch
    If $state Then
   ConsoleWrite ("state: " & $state & " cal: " & $cal & " indx: " & $indx & " Timer: " & $hTimer & " Sleep: " & $RDMSleep & @CRLF)
        If $indx < _GUICtrlListBox_GetCount($idMylist) Then

            If Not $cal Then
                $RDMSleep = Random(2, 4, 1) * 1000
                $hTimer = TimerInit()
                $cal = 1
            ElseIf TimerDiff($hTimer) > $RDMSleep Then
                ConsoleWrite(_GUICtrlListBox_GetText($idMylist, $indx) & @CRLF)
                $indx += 1
                $cal = 0
            EndIf
        Else
            $state = 0
;           GUICtrlSetData($idButton_Run, "Start")
            AdlibRegister("_MyTimerReRunFunc")
        EndIf
    EndIf
WEnd

Func _MyTimerReRunFunc()
    $Minutes = GUICtrlRead($tReRunTimer) ; will wait 90 minutes
    Local $60Count = 0, $begin = TimerInit()
    While $Minutes > $60Count
        $dif = TimerDiff($begin)
        $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
        $Count = int($dif/1000)
        $60Count = Int($Count / 60)
        ToolTip("Minutes Required = " & $Minutes & @CRLF & "Minutes Past = " & $60Count & @CRLF & "Seconds Count = " & $Count & @CRLF & "Mili-Seconds Count = " & $dif2, 20, 20, "Time Machine #1", 1)
        Sleep(20)
    WEnd
    $state = 1
    $indx = 0
AdlibUnRegister("_MyTimerReRunFunc")
EndFunc

Func _Fill_List()

    ; Read the file into an array
    Local $array
    _FileReadToArray($rejserspath, $array)
    ; Check we read something
    If IsArray($array) Then
        ; Convert to a string with delimiters
        $sList = ""
        For $i = 1 To $array[0]
            $sList &= "|" & $array[$i]
        Next
        ; And fill the list
        GUICtrlSetData($idMylist, $sList)
    EndIf

EndFunc

 

Yours sincerely

Kenneth.

Link to comment
Share on other sites

Nice attempt @Valnurat.  Yep you are quite close.  Here my suggestion, it streamlines a bit the program :

#include <Array.au3>
#include <IE.au3>
;#include "WinHttp.au3"
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>

Opt("MustDeclareVars", 1)

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
    , ["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
    , ["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:", 10, 10)
Local $idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:", 10, 52)
Local $idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:", 10, 95)
Local $idDate = GUICtrlCreateDate("", 10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

Local $idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

GUICtrlCreateLabel("Time to rerun", 10, 180)
Global $idTimeToRerun = GUICtrlCreateInput("45", 10, 230, 30, 20)
Global $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
  _Fill_List()
EndIf

Global $state, $indx, $cal
Local $sOrigin, $sDest, $RDMSleep, $hTimer

AdlibRegister(_TimeToRerun, GUICtrlRead($idTimeToRerun) * 1000 * 60)

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Local $sFill = ""
      For $i = 0 To _GUICtrlListBox_GetCount($idMylist) - 1
        $sFill &= _GUICtrlListBox_GetText($idMylist, $i) & "|"
      Next
      $sFill = StringTrimRight($sFill, 1)
      _ArrayAdd($aTmpRejser, $sFill)
      _FileWriteFromArray($Rejserspath, $aTmpRejser)
      ExitLoop
    Case $idButton_AddTrip
      $sOrigin = GUICtrlRead($idComboFra)
      $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
      $sDest = GUICtrlRead($idComboTil)
      $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
      _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
      ;       Case $idButton_Clear
      ;           GUICtrlSetData($idMylist, "")
    Case $idButton_Run
      If $state Then
        _ResetTimer()
      Else
        _TimeToRerun()
      EndIf
    Case $idTimeToRerun
      AdlibRegister(_TimeToRerun, GUICtrlRead($idTimeToRerun) * 1000 * 60)
  EndSwitch
  If $state Then
    If $indx < _GUICtrlListBox_GetCount($idMylist) Then
      If Not $cal Then
        $RDMSleep = Random(2, 4, 1) * 1000
        $hTimer = TimerInit()
        $cal = 1
      ElseIf TimerDiff($hTimer) > $RDMSleep Then
        ConsoleWrite(_GUICtrlListBox_GetText($idMylist, $indx) & @CRLF)
        $indx += 1
        $cal = 0
      EndIf
    Else
      _ResetTimer()
    EndIf
  EndIf
WEnd

Func _Fill_List()
  ; Read the file into an array
  Local $array, $sList
  _FileReadToArray($Rejserspath, $array)
  ; Check we read something
  If IsArray($array) Then
    ; Convert to a string with delimiters
    $sList = ""
    For $i = 1 To $array[0]
      $sList &= "|" & $array[$i]
    Next
    ; And fill the list
    GUICtrlSetData($idMylist, $sList)
  EndIf
EndFunc   ;==>_Fill_List

Func _TimeToRerun()
  $state = 1
  $indx = 0
  $cal = 0
  GUICtrlSetData($idButton_Run, "Stop")
  AdlibUnRegister()
  GUICtrlSetState($idTimeToRerun, $GUI_DISABLE)
EndFunc   ;==>_TimeToRerun

Func _ResetTimer()
  $state = 0
  GUICtrlSetData($idButton_Run, "Start")
  AdlibRegister(_TimeToRerun, GUICtrlRead($idTimeToRerun) * 1000 * 60)
  GUICtrlSetState($idTimeToRerun, $GUI_ENABLE)
EndFunc   ;==>_ResetTimer

Did not test much, but looks alright, let me know...

Link to comment
Share on other sites

As it is now, the start button is enable while it is waiting for the next run.

And when the waiting mode is over the button goes back to "Stop".

I just want to have the option to stop it no matter if it is in waiting mode or in progress mode.

Yours sincerely

Kenneth.

Link to comment
Share on other sites

6 minutes ago, Valnurat said:

As it is now, the start button is enable while it is waiting for the next run.

Yes you can manually start (by clicking button) or wait to automatically start (after delay)

7 minutes ago, Valnurat said:

And when the waiting mode is over the button goes back to "Stop".

Yes, when it is manually or automatically started, you can stop the display (ConsoleWrite) anytime

8 minutes ago, Valnurat said:

I just want to have the option to stop it no matter if it is in waiting mode or in progress mode.

You can perform the changes you need.  I was understanding differently the function of the button Start/Stop vs the delay.  Now it is up to you to adapt the code to your requirements :)

Link to comment
Share on other sites

I'm getting a brain meltdown about this. I'm trying to have this fixed and I tried to find out how I can see if the Stop button is pressed. So I tried something, but I can't get it to work.

#include <Array.au3>
#include <IE.au3>
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>
Opt("MustDeclareVars", 1)

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
    , ["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
    , ["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:", 10, 10)
Local $idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:", 10, 52)
Local $idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:", 10, 95)
Local $idDate = GUICtrlCreateDate("", 10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

Local $idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

GUICtrlCreateLabel("Time to rerun", 10, 180)
Global $idTimeToRerun = GUICtrlCreateInput("1", 10, 230, 30, 20)
Global $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
  _Fill_List()
EndIf

Global $state, $indx, $cal, $button_pressed
Local $sOrigin, $sDest, $RDMSleep, $hTimer

;AdlibRegister(_TimeToRerun, GUICtrlRead($idTimeToRerun) * 1000 * 60)

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Local $sFill = ""
      For $i = 0 To _GUICtrlListBox_GetCount($idMylist) - 1
        $sFill &= _GUICtrlListBox_GetText($idMylist, $i) & "|"
      Next
      $sFill = StringTrimRight($sFill, 1)
      _ArrayAdd($aTmpRejser, $sFill)
      _FileWriteFromArray($Rejserspath, $aTmpRejser)
      ExitLoop
    Case $idButton_AddTrip
      $sOrigin = GUICtrlRead($idComboFra)
      $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
      $sDest = GUICtrlRead($idComboTil)
      $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
      _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
      ;       Case $idButton_Clear
      ;           GUICtrlSetData($idMylist, "")
  Case $idButton_Run

      If $state Then
            MsgBox(0,"ButtonPressed " & $state,"ResetTimer")
        $button_pressed = 1
        _ResetTimer()
      Else
            MsgBox(0,"ButtonPressed " & $state,"TimeToRerun")
        _TimeToRerun()
      EndIf
#cs    Case $idTimeToRerun
    MsgBox(0,GUICtrlRead($idTimeToRerun),"idTimeToRerun")
#ce      AdlibRegister(_TimeToRerun, GUICtrlRead($idTimeToRerun) * 1000 * 60)
  EndSwitch
  If $state Then
    If $indx < _GUICtrlListBox_GetCount($idMylist) Then
      If Not $cal Then
        $RDMSleep = Random(2, 4, 1) * 1000
        $hTimer = TimerInit()
        $cal = 1
      ElseIf TimerDiff($hTimer) > $RDMSleep Then
        ConsoleWrite(_GUICtrlListBox_GetText($idMylist, $indx) & @CRLF)
        $indx += 1
        $cal = 0
      EndIf
    Else
      _ResetTimer()
    EndIf
  EndIf
WEnd

Func _TimeToRerun()
    MsgBox(0,$button_pressed,"TimeToRerun")
  $state = 1
  $indx = 0
  $cal = 0
  GUICtrlSetData($idButton_Run, "Stop")
  AdlibUnRegister()
  GUICtrlSetState($idTimeToRerun, $GUI_DISABLE)
EndFunc   ;==>_TimeToRerun

Func _ResetTimer()
    MsgBox(0,$button_pressed,"ResetTime")
  If not $button_pressed Then
    $state = 1
    AdlibRegister(_TimeToRerun, GUICtrlRead($idTimeToRerun) * 1000 * 60)
  Else
    $state = 0
    $button_pressed = 0
    GUICtrlSetData($idButton_Run, "Start")
    GUICtrlSetState($idTimeToRerun, $GUI_ENABLE)
    AdlibUnRegister()
  EndIf
EndFunc   ;==>_ResetTimer

Func _Fill_List()
  ; Read the file into an array
  Local $array, $sList
  _FileReadToArray($Rejserspath, $array)
  ; Check we read something
  If IsArray($array) Then
    ; Convert to a string with delimiters
    $sList = ""
    For $i = 1 To $array[0]
      $sList &= "|" & $array[$i]
    Next
    ; And fill the list
    GUICtrlSetData($idMylist, $sList)
  EndIf
EndFunc   ;==>_Fill_List

I'm using the msgbox to debug as I don't know to follow the code.

Yours sincerely

Kenneth.

Link to comment
Share on other sites

10 hours ago, Valnurat said:

I just want to have the option to stop it no matter if it is in waiting mode or in progress mode.

What do you want to stop ?  Please take your time to explain clearly what you want, otherwise I will not be able to help you.  I already invested much time in your project.  I will not invest more until you distinctively define your expectations.

Link to comment
Share on other sites

@Nine I believe Valnurat is trying to stop adlib function when it is in wait mode.

My limited knowledge tells me, since, there is only 1 button and 2 states, you can only have 2 options and need to introduce another variable. Maybe, use _isPressed to check for if, say, SHIFT key is pressed while clicking and stop everything if so?

Edited by GokAy
Link to comment
Share on other sites

2 minutes ago, GokAy said:

I believe Valnurat is trying to stop adlib function when it is in wait mode.

Then just unregister the function.  I am not very good at the guessing game, I guess.  

Link to comment
Share on other sites

8 hours ago, Nine said:

Then just unregister the function.  I am not very good at the guessing game, I guess.  

That is what I'm trying, but I can't distinguish between state of the start and stop, as it is the same button I'm using.

Yours sincerely

Kenneth.

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