ZeroByDevide Posted October 6, 2016 Share Posted October 6, 2016 so right now i have a small project and i wanted to print this text out every second. i have made a random number for the sleep function. but when i want to print out with the while loop it just doesn't work. Run("notepad.exe") Sleep(1000) Local $rndSleep = Int (Random(180000,240000,1000)) While $rndSleep <> 0 $rndSleep - 1 If Mod ( $rndSleep, 1000 ) == 0 Then Send("This note will show the sleeptime before closing the tabs, you got " & $rndSleep & " seconds left.") EndIf WEnd plis halp me Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2016 Moderators Share Posted October 6, 2016 (edited) ZeroByDevide, This works for me: Local $rndSleep = Int (Random(180,240,1)) $iSec = @SEC While 1 If $iSec <> @SEC Then $iSec = @SEC $rndSleep -= 1 If $rndSleep Then ConsoleWrite("This note will show the sleeptime before closing the tabs, you got " & $rndSleep & " seconds left." & @CRLF) Else ExitLoop EndIf EndIf ; Important to let the CPU breathe Sleep(10) WEnd M23 Edited October 6, 2016 by Melba23 Amended code weirddave 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ZeroByDevide Posted October 6, 2016 Author Share Posted October 6, 2016 THanks!! Link to comment Share on other sites More sharing options...
weirddave Posted October 6, 2016 Share Posted October 6, 2016 There are few errors in the original code: ; this won't do anything $rndSleep - 1 ;you need $rndSleep -= 1 This might be of help:https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm ;this will work If Mod ( $rndSleep, 1000 ) == 0 Then ;but you should use If Mod ( $rndSleep, 1000 ) = 0 Then ;as == is for comparing strings, so there is extra work being done to convert both sides of the comparison to strings Other problems with the code are: 1) It won't display the text every second, it will display every 1000 loops of the code, which will depend on the CPU speed. 2) There's no carriage return, so the text will display all on the same (long) line. Add & @CRLF to the send command. 3) If you click on a different window, that window will receive the text, this could cause problems Melbas solution has a problem, it doesn't stop at 0 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2016 Moderators Share Posted October 6, 2016 weirddave, Quote Melbas solution has a problem, it doesn't stop at 0 It does now - thanks for the prompt! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now