
nobrainer612
Members-
Posts
13 -
Joined
-
Last visited
Everything posted by nobrainer612
-
Get specific numbers from website
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Thank you very much. I looked at the document, tried the code and it worked! Have a nice day and thanks once again -
Get specific numbers from website
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Thank you so much. I have a question. Below is the code of my rollover rate calculator application. I added a menu item "Request both rates" that allows users to look at the 2 tables with exchange rates and interest rate. But when I tried to close the table, it would not close. And when I pressed "close" one more time, it closed the whole application. I want to see if this is normal. #include <IE.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\Ric\Desktop\au3\Roll_Over_Calculator.kxf Global $MaxArrayItem = 30 Global $MaxArrayItem_2 = 11 Global $ComboArray[$MaxArrayItem] = ["-- Major Currency Pairs --", "EUR/USD", "USD/JPY", "GBP/USD", "USD/CHF", "USD/CAD", "AUD/USD", "NZD/USD", "-- Minor Currency Pairs --", "EUR/CHF", "EUR/GBP", "EUR/CAD", "EUR/AUD", "EUR/NZD", "EUR/JPY", "GBP/JPY", "CHF/JPY", "CAD/JPY", "AUD/JPY", "NZD/JPY", "GBP/CHF", "GBP/AUD", "GBP/CAD", "GBP/NZD", "AUD/CHF", "AUD/CAD", "AUD/NZD", "CAD/CHF", "NZD/CHF","NZD/CAD"] Global $ComboArray_2[$MaxArrayItem_2] = ["-- Other Currency Pairs --","EUR/TRY", "USD/TRY", "USD/SEK", "USD/NOK", "USD/DKK", "USD/ZAR", "USD/HKD", "USD/SGD", "USD/THB", "USD/MXN"] Global $MaxArrayItem_Contract_Size = 3 Global $ComboArray_Contract_Size[$MaxArrayItem_Contract_Size] = ["Standard Lot", "Mini Lot", "Micro Lot"] $Roll_Over_Calculator = GUICreate("Roll Over Calculator", 615, 440, 192, 124) $Group1 = GUICtrlCreateGroup(" Roll Over Calculator ", 24, 32, 561, 393) $Label1 = GUICtrlCreateLabel("Please select the currency pairs you are buying/selling in:", 40, 72, 274, 17) $Combo1 = GUICtrlCreateCombo("", 320, 72, 121, 25, BitOR($CBS_DROPDOWNLIST ,$CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Button3 = GUICtrlCreateButton("More", 450, 70, 105, 25) $Exchange_Rate_Label = GUICtrlCreateLabel("The currency exchange rate: ", 173, 101, 140, 17) $Exchange_Rate_Input = GUICtrlCreateInput("", 320, 99, 121, 20) $Button4 = GUICtrlCreateButton("Set Currency Pairs", 450, 95, 105, 25) GUICtrlSetData($Combo1, "|") For $i = 0 To 29 GUICtrlSetData($Combo1, $ComboArray[$i]) Next $Label2 = GUICtrlCreateLabel("'s Currenly Interest Rate:", 32, 128, 160, 17) $Label3 = GUICtrlCreateLabel("'s Currenly Interest Rate:", 32, 160, 160, 17) $Input1 = GUICtrlCreateInput("", 170, 128, 89, 21) $Input2 = GUICtrlCreateInput("", 170, 160, 89, 21) $Label4 = GUICtrlCreateLabel("Contract Size:", 280, 192, 70, 17) $Input3 = GUICtrlCreateInput("", 360, 192, 41, 21) $check1 = GUICtrlcreateCheckbox("", 32, 192, 20, 20) $check2 = GUICtrlcreateCheckbox("", 150, 192, 20, 20) $Label_checkbox1 = GUICtrlCreateLabel("Buy ", 55, 195, 80, 17) $Label_checkbox2 = GUICtrlCreateLabel("Sell ", 170, 195, 80, 17) $Combo2 = GUICtrlCreateCombo("-- Contract Type --", 416, 192, 121, 25, BitOR($CBS_DROPDOWNLIST ,$CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData($Combo2, "|") For $i = 0 To 2 GUICtrlSetData($Combo2, $ComboArray_Contract_Size[$i]) Next $Label5 = GUICtrlCreateLabel("For the Contract Size, please enter the amount and the lot type.", 280, 128, 302, 17) $Label6 = GUICtrlCreateLabel("Example: 2 Standard Lot", 280, 152, 120, 17) $Button1 = GUICtrlCreateButton("Calculate", 112, 248, 105, 25) $Button2 = GUICtrlCreateButton("Reset", 352, 248, 105, 25) $Label7 = GUICtrlCreateLabel("Result of Calculation:", 40, 312, 104, 17) $Label9 = GUICtrlCreateLabel("Daily Rate Received:", 40, 352, 400, 17) ;$Label9 = GUICtrlCreateLabel("Daily Rate Received:", 304, 352, 200, 17) $menu1 = GuiCtrlCreateMenu("File") $help = GuiCtrlCreateMenuItem("Help", $menu1) $exit = GuiCtrlCreateMenuItem("Exit", $menu1) $menu2 = GuiCtrlCreateMenu("Request Rates") $request_interest_rate = GuiCtrlCreateMenuItem("Request Interest Rate", $menu2) $request_exchange_rate = GuiCtrlCreateMenuItem("Request Exchange Rate", $menu2) $request_both_rate = GuiCtrlCreateMenuItem("Request Both Rates", $menu2) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Base Global $Quote GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Calculate() Case $Button2 Reset() Case $Button3 More_Pairs() Case $Button4 Set_Currency_Pairs() Case $help Help() Case $exit() Exit_Func() Case $request_interest_rate Request_interest_rate() Case $request_exchange_rate Request_exchange_rate() Case $request_both_rate Request_both_rate() EndSwitch WEnd Func Request_both_rate() $oIE = _IECreate("http://www.dailyfx.com/", 0, 0) $eIE = _IECreate("http://www.xe.com/", 0, 0) $oTable = _IETableGetCollection($oIE, 18) $eTable = _IETableGetCollection($eIE, 0) $aTableData = _IETableWriteToArray($oTable, 1) $eTableData = _IETableWriteToArray($eTable, 1) _IEQuit($oIE) _IEQuit($eIE) For $i = 2 To 6 step 2 For $j = 10 to 1 step -1 $eTableData[$i][$j] = $eTableData[$i][$j-1] Next Next GuiCreate("Currency Rate and Exchange Rate", 650, 500) $listview = GUICtrlCreateListView("Currency|Central Bank Rate|Overnight Rate ", 10, 10, 303, 180) For $i = 1 To UBound($aTableData)-1 GUICtrlCreateListViewItem($aTableData[$i][0] &"|"& $aTableData[$i][1] &"|"& $aTableData[$i][2], $listview) Next GUISetState() $listview = GUICtrlCreateListView("Currecny|USD|EUR|GBP|INR|AUD|CAD|ZAR|NZD|JPY ", 10, 200, 630, 280) For $i = 1 To UBound($eTableData)-1 GUICtrlCreateListViewItem($eTableData[$i][1] &"|"& $eTableData[$i][2]&"|"& $eTableData[$i][3]&"|"& $eTableData[$i][4]&"|"& $eTableData[$i][5]&"|"& $eTableData[$i][6]&"|"& $eTableData[$i][7]&"|"& $eTableData[$i][8]&"|"& $eTableData[$i][9]&"|"& $eTableData[$i][10], $listview) Next GUISetState() While GUIGetMsg()<>-3 Wend EndFunc Func Request_interest_rate() $oIE = _IECreate("http://www.dailyfx.com/", 0, 0) $oTable = _IETableGetCollection($oIE, 18) $aTableData = _IETableWriteToArray($oTable, 1) _IEQuit($oIE) _ArrayDisplay($aTableData) EndFunc Func Request_exchange_rate() $oIE = _IECreate("http://www.xe.com/", 0, 0) $oTable = _IETableGetCollection($oIE, 0) $aTableData = _IETableWriteToArray($oTable, 1) _IEQuit($oIE) For $i = 2 To 6 step 2 For $j = 10 to 1 step -1 $aTableData[$i][$j] = $aTableData[$i][$j-1] Next Next _ArrayDisplay($aTableData) EndFunc Func Calculate() Global $Base_Input = GUICtrlRead($Input1) Global $Quote_Input = GUICtrlRead($Input2) Global $Contract_amount = GUICtrlRead($Input3) Global $Contract_type = GUICtrlRead($Combo2) Global $Check1_input = GUICtrlRead($check1) Global $Check2_input = GUICtrlRead($check2) Global $Exchange_Rate = GUICtrlRead($Exchange_Rate_Input) if $Base = "" AND $Quote = "" Then msgbox(0,"No selected currency pair", "Please select a currency pair.") ElseIf $Exchange_Rate = "" Then msgbox(0,"Empty Input", "Please enter the current exchange rate of the currency pair.") ElseIf StringIsInt($Exchange_Rate) = 0 And StringIsFloat($Exchange_Rate) = 0 Then msgbox(0,"Incorrect Input", "Please enter the correct value for the exchange rate.") ElseIf $Base_Input = "" Or $Quote_Input = "" Then msgbox(0,"Empty Inputs", "Please make sure you enter the interest rate for both currencies.") ElseIf StringIsInt($Base_Input) = 0 And StringIsFloat($Base_Input) = 0 Then msgbox(0,"Incorrect type of Inputs", "Please make sure your enter correct value for the Base currency's interest rate.") ElseIf StringIsInt($Quote_Input) = 0 AND StringIsFloat($Quote_Input) = 0 Then msgbox(0,"Incorrect type of Inputs", "Please make sure your enter correct value for the Quote currency's interest rate.") ElseIf $Contract_amount = "" Or $Contract_type = "" Then msgbox(0,"Empty Contract Size", "Please enter the value and the type of your contract size.") ElseIf StringIsInt($Contract_amount) = 0 And StringIsFloat($Contract_amount) = 0 Then msgbox(0,"Incorrect type of Inputs", "Please enter correct value for the value of your contract size.") ElseIf BitAnd($Check1_input, $GUI_CHECKED) And BitAnd($Check2_input, $GUI_CHECKED) Then msgbox(0,"Both checkboxes are checked", "Please choose either buy or sell.") ElseIf BitAnd($Check1_input, $GUI_UNCHECKED) And BitAnd($Check2_input, $GUI_UNCHECKED) Then msgbox(0,"No Decision", "Please choose either buy or sell.") Else if $Contract_type = "Standard Lot" Then $lot_size = 100000 Call("Calculation_Start", $lot_size, $Contract_amount) if BitAnd($Check1_input, $GUI_CHECKED) Then GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Result_to_match_quote,6) & " " & $Quote & " or " & Round($Result_to_match_base,6) & " " & $Base) Else GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Selling_Result_to_match_base,6) & " " & $Quote & " or " & Round($Selling_Result_to_match_quote,6) & " " & $Base) EndIf ElseIf $Contract_type = "Mini Lot" Then $lot_size = 10000 Call("Calculation_Start", $lot_size, $Contract_amount) if BitAnd($Check1_input, $GUI_CHECKED) Then GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Result_to_match_quote,6) & " " & $Quote & " or " & Round($Result_to_match_base,6) & " " & $Base) Else GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Selling_Result_to_match_quote,6) & " " & $Quote & " or " & Round($Selling_Result_to_match_base,6) & " " & $Base) EndIf Else $lot_size = 1000 Call("Calculation_Start", $lot_size, $Contract_amount) if BitAnd($Check1_input, $GUI_CHECKED) Then GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Result_to_match_quote,6) & " " & $Quote & " or " & Round($Result_to_match_base,6) & " " & $Base) Else GUICtrlSetData($Label9, "Daily Rate Received: " & Round($Selling_Result_to_match_base,6) & " " & $Quote & " or " & Round($Selling_Result_to_match_quote,6) & " " & $Base) EndIf EndIf EndIf EndFunc Func Calculation_Start($lot_size, $Contract_amount) ;Calculating First base currency: $total_size = $lot_size * $Contract_amount $Base_currency_interest_yearly = ($total_size * $Base_Input)/100 $Base_currency_interest_daily = $Base_currency_interest_yearly/365 ;Calculating Second Quote currency: $Total_Quote_currency_after_exchange_rate = $total_size * $Exchange_Rate $Quote_currency_interest_yearly = ($Total_Quote_currency_after_exchange_rate * $Quote_Input)/100 $Quote_currency_interest_daily = $Quote_currency_interest_yearly/365 ;Converting Base currency to same currency type $After_convert_to_match_quote = $Base_currency_interest_daily * $Exchange_Rate $After_convert_to_match_base = $Quote_currency_interest_daily / $Exchange_Rate ;Get the result Global $Result_to_match_quote = $After_convert_to_match_quote - $Quote_currency_interest_daily Global $Result_to_match_base = $Base_currency_interest_daily - $After_convert_to_match_base ;For Selling Global $Selling_Result_to_match_quote = $Quote_currency_interest_daily - $After_convert_to_match_quote Global $Selling_Result_to_match_base = $After_convert_to_match_base - $Base_currency_interest_daily EndFunc Func More_Pairs() $Combo_count = _GUICtrlComboBox_GetCount($Combo1) if $Combo_count = 30 Then GUICtrlSetData($Combo1, "|") For $i = 0 To 10 GUICtrlSetData($Combo1, $ComboArray_2[$i]) Next Else GUICtrlSetData($Combo1, "|") For $i = 0 To 29 GUICtrlSetData($Combo1, $ComboArray[$i]) Next EndIf EndFunc Func Set_Currency_Pairs() $Currency_Pair = GUICtrlRead($Combo1) if $Currency_Pair = "-- Major Currency Pairs --" Then msgbox(0,"Selection Error","Please select a currency pair") ElseIf $Currency_Pair = "-- Minor Currency Pairs --" Then msgbox(0,"Selection Error","Please select a currency pair") Elseif $Currency_Pair = "-- Other Currency Pairs --" Then msgbox(0,"Selection Error","Please select a currency pair") Elseif $Currency_Pair = "" Then msgbox(0,"Selection Error","Please select a currency pair") Elseif _GUICtrlComboBox_SelectString($Combo1,$Currency_Pair) = -1 And _GUICtrlComboBox_SelectString($Combo2,$Currency_Pair) = -1 Then msgbox(0,"No such currency pair.","No such currency pair.") Else $Currency_Pair_Split = StringSplit($Currency_Pair, "/") Global $Base = $Currency_Pair_Split[1] Global $Quote = $Currency_Pair_Split[2] GUICtrlSetData($Label2, $Base & "'s Currenly Interest Rate:") GUICtrlSetData($Label3, $Quote & "'s Currenly Interest Rate:") GUICtrlSetData($Label_checkbox1, "Buy " & $Currency_Pair) GUICtrlSetData($Label_checkbox2, "Sell " & $Currency_Pair) EndIf EndFunc Func Help() msgBox(0, "Help", "The calculator is implemented according to the RollOver Rate tutorial in DailyFx, Please go to the link below to check out the tutorial!" & @LF & "" & @LF& "http://www.dailyfx.com/forex/education/learn_forex/the_basics/making_a_forex_trade/4/2009-10-14-0101-Rollover.html ") EndFunc Func Exit_Func() $exit_confirm = msgBox(4, "Exit the Application", "Do you want to exit this application?") if $exit_confirm = 6 Then Exit EndIf EndFunc Func Reset() GUICtrlSetData($Input1, "") GUICtrlSetData($Input2, "") GUICtrlSetData($Input3, "") GUICtrlSetData($Exchange_Rate_Input , "") GUICtrlSetState($Check1,$GUI_UNCHECKED) GUICtrlSetState($Check2,$GUI_UNCHECKED) EndFunc -
Get specific numbers from website
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
ok I will go take a look at listviews. Thank you -
Get specific numbers from website
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Thank you Mr.kikell for the explanation, and now I understand how they work. I created 2 buttons. One for getting the interest rate table and another one for getting the exchange rate. And I found that one table must be closed before another opens. (They can not display together) Then I tried to find a way to allow 2 tables show up together, and I found one tutorial about interrupt. http://www.autoitscript.com/wiki/Interrupting_a_running_function But they used for loop to keep checking for interrupt. Does that mean interrupt can not be used in my code? or are there any way to let 2 tables show up together? Thank you once again for your time. I am learning a lot from you! -
Get specific numbers from website
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Dear Mr: mikell: At this moment, I have 2 questions I do not quite understand. The first one is, I understand you got the inverse rates from www.xe.com by using the loop (those msgbox are there just for me to look at those values) For $i = 2 To 6 step 2 For $j = 10 to 1 step -1 $aTableData[$i][$j] = $aTableData[$i][$j-1] msgbox(0,"i",$i) msgBox(0,"j",$j) msgBox(0,"j",$aTableData[$i][$j-1]) msgBox(0,"j",$aTableData[$i][$j]) Next Next But how did you get those non-inverse ones? Even though I saw the pop up table shows both non-inverse rates and the inverse rates, I do not find the loop that get the non-inverse rates. Sorry if my question is a little bit stupid. and my second question is: from this line, why is the $i_index = 18? how do I determine that? Thank you so much for your help. $oTable = _IETableGetCollection($oIE, 18) -
Get specific numbers from website
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Thank you very much for the replies, and I will take a good deep look at these. And I just found this topic as well '?do=embed' frameborder='0' data-embedContent>> and I believe this will help me a lot as well. Thank you again for all your time, Mr mikell and Mr.water -
Get specific numbers from website
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
yes. I want to get the exchange rate from this currency exchange website http://www.xe.com/ and the bank rate from dailyfx.com (there is a chart at the bottom for bank rate) http://www.dailyfx.com/ Are there any way to get those from commands? -
Hello everyone, thank you for helping me out. I program with AutoIT Script for about 2-3 months, so I am trying to get familiar with it. I created a roll-over rate calculator because I thought that was pretty interesting. I put the source code and the application on my website. http://www.hau-wai-kit.com/Rollover_calculator It can calculate the roll-over rate if the user enters which currency pairs they want to trade, the currency exchange rate of the currency pairs, and both of the currency's interest rate. Users need to enter all these rates manually, which means they need to go to the central bank website, check the rate and enter into the application. I want to make this application easier for general use. So is there any way to get numbers/rate from website directly? Thank you so much.
-
Stop the timer when a stop button is pressed
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Oh wow. That is amazing. Thanks for the code. I think my understanding of Timer is not good enough, that is why I am stuck. But I learned a lot from this. Thanks again. -
Stop the timer when a stop button is pressed
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Thank you for your reply. Right now I am able to stop the timer using TimerDiff, but I have no idea how to resume. It will just restart the whole counting process. Below is my code: #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Date.au3> $Form1_1 = GUICreate("Timer", 615, 393, 192, 124) $Label2 = GUICtrlCreateLabel("Timer: ", 40, 120, 49, 25) GUICtrlSetColor(-1, 0x008000) $Label3 = GUICtrlCreateLabel("0 seconds", 136, 120, 80, 25) $Start_Button = GUICtrlCreateButton("Start Timer", 360, 120, 120, 33) $Stop_Button = GUICtrlCreateButton("Stop Timer", 488, 120, 120, 33) $Reset_Button = GUICtrlCreateButton("Reset Timer", 360, 160, 120, 33) $Resume_Button = GUICtrlCreateButton("Resume Timer", 488, 160, 120, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $timer, $Secs, $Mins, $Hour, $Time, $current_left While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Start_Button $finished = 5 $timer = TimerInit() AdlibRegister("Timer", 250) Case $Stop_Button StopTimer() Case $Reset_Button ResetTimer() Case $Resume_Button ResumeTimer() EndSwitch WEnd Func Timer() _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs) Local $sTime = $Time ; save current time to be able to test and avoid flicker.. if $finished - $Secs >= 0 Then ;MsgBox(0,"Stop",int(TimerDiff($timer))) GuiCtrlSetData($Label3, $finished - $Secs & " seconds") Else EndIf EndFunc Func StopTimer() $timer= TimerDiff($timer) Global $dif = TimerDiff($timer) global $current_left = $finished - $Secs GuiCtrlSetData($Label3, $current_left & " seconds") ;MsgBox(0,"Stop",$dif) ;MsgBox(0,"Stop",$current_left) EndFunc Func ResetTimer() EndFunc Func ResumeTimer() $timer = $timer - $dif $timer = TimerInit() AdlibRegister("Timer", 250) _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs) GuiCtrlSetData($Label3, $current_left & " seconds") if $current_left - $Secs >= 0 Then ;MsgBox(0,"Stop",int(TimerDiff($timer))) GuiCtrlSetData($Label3, $current_left - $Secs & " seconds") Else EndIf EndFunc -
Stop the timer when a stop button is pressed
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Hello, I wrote the code below that able to count down from given time to 0. When I pressed the stop button, it will put the current number put into a variable. But my problem is, how do I stop the counter from counting after I press the stop button? Thank you so much. #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Date.au3> $Form1_1 = GUICreate("Timer", 615, 393, 192, 124) $Label2 = GUICtrlCreateLabel("Timer: ", 40, 120, 49, 25) GUICtrlSetColor(-1, 0x008000) $Label3 = GUICtrlCreateLabel("0 seconds", 136, 120, 80, 25) $Start_Button = GUICtrlCreateButton("Start Timer", 360, 120, 120, 33) $Stop_Button = GUICtrlCreateButton("Stop Timer", 488, 120, 120, 33) $Reset_Button = GUICtrlCreateButton("Reset Timer", 360, 160, 120, 33) $Resume_Button = GUICtrlCreateButton("Resume Timer", 488, 160, 120, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $timer, $Secs, $Mins, $Hour, $Time, $current_left While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Start_Button $finished = 5 $timer = TimerInit() AdlibRegister("Timer", 250) Case $Stop_Button StopTimer() Case $Reset_Button ResetTimer() Case $Resume_Button ResumeTimer() EndSwitch WEnd Func Timer() _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs) Local $sTime = $Time if $finished - $Secs >= 0 Then GuiCtrlSetData($Label3, $finished - $Secs & " seconds") Else EndIf EndFunc Func StopTimer() $current_left = $finished - $Secs GuiCtrlSetData($Label3, $finished - $Secs & " seconds") MsgBox(0,"Stop",$current_left) EndFunc -
Stop the timer when a stop button is pressed
nobrainer612 replied to nobrainer612's topic in AutoIt General Help and Support
Thanks for the tips. I will try to finish the code using TimerDiff and _TicksToTime -
Hello, I am trying to build a timer for a mini game. This time will count down from a sepcific time to 0. I wrote the code below to perform that task. But I am stuck in the part that when I press a button to stop the timer and resume when I press another button. I don't know how to pause the count down and save the current number $i and pass back to resume function. I hope somebody can give me some ideas, thank you so much! While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Start_Button StartTimer(90) Case $Stop_Button StopTimer() Case $Resume_Button ResumeTimer() EndSwitch WEnd Func StartTimer($Timer) global $i = $Timer Do GuiCtrlSetData($Label3, $i & " second") $i = $i - 1 Sleep(1000) Until $i == 0 EndFunc Func StopTimer() EndFunc Func ResumeTimer() EndFunc