iamtheky Posted April 15, 2017 Share Posted April 15, 2017 6 minutes ago, czardas said: Why do I get that funny feeling that someone's thinking of completely redrafting the Help File If you say that 3 times into a silvered mirror then @guinness will appear and smite you. czardas 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Danyfirex Posted April 15, 2017 Share Posted April 15, 2017 (edited) I think topic about answer is going out of the scope (no variables one haha) Because answer is already answered. If were talking about an answer. czardas's one is clear and correct at least for me. the one with ternary operator is correct too. But We're no talking about make our code shorter. talking about out topic (variable scope) I usually do something like this. ;~ when I do Scripts with many functions I put all my global variables at script's top with the Global keyword. #Region Sample-1 Global $g_sSomething="Something" ;do something here Func _Func1() ;probably use my $g_sSomething EndFunc Func _Func2() ;probably use my $g_sSomething Local $sSomething="Something local here" ;similar name as global one but using variable naming EndFunc #EndRegion ;But when I create Scripts (usally small scripts) without functions(Predefined) I use always Local keyword #Region Sample-2 local $g_sSomething="Something" ConsoleWrite($g_sSomething & @CRLF) #EndRegion Saludos Edited April 15, 2017 by Danyfirex czardas 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
mikell Posted April 15, 2017 Share Posted April 15, 2017 Hmmm. So from now on I will explain to beginners : "you need a global variable ? then use Local, because Global is not reliable" And when they will ask me : "so what is the usefulness of this Global keyword mentioned a lot of times in the help file ?" I will answer : "I have a temporary headache. Please ask czardas" TheSaint 1 Link to comment Share on other sites More sharing options...
iamtheky Posted April 15, 2017 Share Posted April 15, 2017 reminding your future self (or whomever is unlucky enough to maintain your code) of what you were doing. I believe I have also heard: "Just in case future AutoIt devs make changes, you might want to follow the same conventions they are going to." ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
guinness Posted April 15, 2017 Share Posted April 15, 2017 (edited) I apologise @czardas for hijacking this thread, but thought I would clear a few things up ... I am not working on a new version of the Help File, as the current one seems just fine to me My opinions about Local being used in the help files still stand as correct, especially when you look at it from the point of view that the variable(s) are "local to the scope" i.e. imagine that big space outside of all the functions defined, is wrapped in an imaginary Main function. Since the likes of C/C++/C# require a function entry point normally labelled "main" ; This line is used elsewhere Global $sGlobalVar = '' ; This line can be seen as ... Local $sLanguage = 'JavaScript' ; ... this line, since the variable is not used anywhere else Func Main() Local $sLanguage = 'JavaScript' ConsoleWrite($sLanguage) EndFunc Function SomeOtherFunc() $sGlobalVar = 'A truly globally variable' EndFunc Disclaimer: I am mainly using JavaScript these days anyway, in which I have created my own Promise and Observable polyfills, plus I use the highly respected Airbnb Style Guide for writing clean and understandable JavaScript. Edited April 15, 2017 by guinness czardas 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 (edited) @guinness Please tell me if I have misunderstood you. I see variables which ought to be local (or inside a function) as distinct from those which ought to be global. I generally declare them according to these principles, and nearly all my variables end up inside functions: making everything pretty much watertight. I try to follow your lead (secretly ). So one quick question: would you have used the Global keyword or the Local keyword for the declaration of $iHour in the first post? Edited April 15, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
guinness Posted April 15, 2017 Share Posted April 15, 2017 In that example I would use Local, unless that variable is used also within another scope i.e. a function declaration, which in that case it should be Global. TheSaint 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 Thanks, you explained it a lot better than I did. guinness 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted April 21, 2017 Author Share Posted April 21, 2017 (edited) The following is my suggested solution for the second exercise I posted. Exercise (see link) - post #15 The most obvious problem affecting the countdown is the instruction to exit the loop at the end of the first run. After removing the ExitLoop instruction, you will see that it made no difference and that the countdown is still broken. It is not uncommon to find more than one issue causing the same, similar or related problems. In this case there are two issues preventing the countdown. If you look at Help File example for 'Do . . . Until', you will notice that the last line of the loop ends with an expression using the comparison operator '=' (NOTE: the equals sign is also used as an assignment operator - these are two different things). So what must countdown equal when we blast off? #include <MsgBoxConstants.au3> Local $iCountDown = 5 Do MsgBox($MB_OK, "Houston", $iCountDown, 1) Sleep(1000) $iCountDown -= 1 Until $iCountDown = 0 MsgBox($MB_OK, "Houston", "Blast Off", 1) Now we have fixed the problem, we send the module back to Nasa but they are still not satisfied. Why is that? Further exercises 1. Rewrite the code using a While . . . WEnd loop. 2. Implement an option to abort the countdown using a hotkey. Use the Help File to assist you. Edited April 21, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mikell Posted April 21, 2017 Share Posted April 21, 2017 4 hours ago, czardas said: they are still not satisfied. Why is that? Didn't they say : you shouldn't sleep while a countdown ? czardas 1 Link to comment Share on other sites More sharing options...
czardas Posted April 21, 2017 Author Share Posted April 21, 2017 No sleeping on the job hey! operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mikell Posted April 21, 2017 Share Posted April 21, 2017 Particularly Nasa. Twice more dangerous and when you awake, it's too late 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