marko29 Posted January 13, 2011 Author Share Posted January 13, 2011 marko29, One case where you might need Global other than at the original declaration is if you need to clear a Global array within a function to make sure you only get the elements that will be filled that run. Either you clear the array by clearing each element individually in a loop, or you redeclare the array in the same scope as originally - using Dim is deprecated as you then are not sure quite what scope you have set. : i see your point for Dim, i had no idea its deprecated so i will keep that in mind) Of course, ideally you should try to have as few Global variables as possible - less chance of overwriting them by mistake - so you should not have an enormous list at the top of your script. But it is best to declare them there - declaring a Global variable inside a function is fine when you start coding, but what if you move the function within the script or decide to use the variable in another function which comes earlier in execution? Then i would of course declare it on top, as i said i do it for alot of vars and i dont force myself to declare everything in the function but you know sometimes you just dont see a need to declare anything on the top(just as you dynamically make objects in c++ when and where you need them) I see the point of declaring things on top and i fully understand that sometimes its best choice but every rule has exception, sometimes the function you mention is the only logical place where anything about that variable/array will start, and it will never happen before that function is executed so i dont see ever myself the need to use the var before that point) Experience over the years has shown that declaring Global variables at the start is good practice - ignore that at your own risk and peril! I can respect that point, thanks for explaining things in a logical manner without just telling me i have no idea what i am doing M23 P.S. These are the Au3Check parameters - you set them by adding the #AutoIt3Wrapper_au3check_parameters= directive to the top of your script. Perhaps you can find a setting which better suits your preferred coding style. The default is -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6. Usage: Au3Check [-q] [-d] [-u file] [-w[-] n].. [-v[-] n].. [-I dir].. file.au3 -q : quiet (only error/warn output) -d : as Opt("MustDeclareVars", 1) -I dir : additional directories for searching include files -U -|file : output unreferenced UDFs and global variables -w 1 : already included file (on) -w 2 : missing #comments-end (on) -w 3 : already declared var (off) -w 4 : local var used in global scope (off) -w 5 : local var declared but not used (off) -w 6 : warn when using Dim (off) -v 1 : show include paths/files (off) -v 2 : show lexer tokens (off) Ha, i guess every rule has exceptions or our dear devs wouldnt make this , thanks a bunch for the help sincerely Link to comment Share on other sites More sharing options...
marko29 Posted January 13, 2011 Author Share Posted January 13, 2011 Btw, did you mean ReDim is deprecated? As its easy way to resize array when you need it Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 13, 2011 Moderators Share Posted January 13, 2011 Mat,You are quite right - the Au3Check parameter set I posted is for UDF checking, although personally I use that all the time. The defaults are mentioned in the parameter list in the same post. JohnOne,You are also correct, but as I explained to marko29, experience has shown that it is good practice to declare them all at the top. Ignore it at your own risk and peril. Obfuscator does not move the declarations - if you declare Global in a function, that is where it stays. Using /StripOnly just removes any unused variables from your script - ususally from the include files when your code does not use the specific function in which they are coded and the function has also been removed by Obfuscator. 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...
Moderators Melba23 Posted January 13, 2011 Moderators Share Posted January 13, 2011 (edited) marko29,ReDim is an essential command and is certainly not deprecated in any sense at all! In several threads over the past few years the Devs has suggested that Dim should not be used - and one in particular was all for getting rid of it entirely. I will try and find an example later. M23Edit: That was easy: Dim Edited January 13, 2011 by Melba23  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...
marko29 Posted January 13, 2011 Author Share Posted January 13, 2011 lol @ retards comment there, tbh i was wondering what the hell is Dim good for Link to comment Share on other sites More sharing options...
bo8ster Posted January 13, 2011 Share Posted January 13, 2011 (edited) Wow you really missed the point, hope I didn't mess up your hair. (someone will get that) This is stupid, why would i search where i declared the var if i know i did it in function that actually is the only logical place where i should of declare it. Did you ever see a c++ header? The reason everything is predeclared is because of scope, Autoit already has a Global scope keyword so why would you make a sandwich of hundreds of declarations on the top of your code if you dont need it? Maybe i dont see some other reason someone else can figure but this reasoning you present is just silly narrowminded perception that everyone code is same, in a huge program i like organize things and put everything where it matters, not make a pasta in the top of my code. You can get away with crap like that in AutoIt but not c/++ or Java. I guess you have never worked in a team env on enterprise code. Btw, C++ header is not a script, usually contains a class. Have you seen a C header? Where you tought global vars are best practice? In several days i wrote a mix of spider, scrapper, automation tool with bunch of loops and iterations, still have to post a code here so i have no idea why you think no one can understand my code. want a t-shirt? You can code any way you wish, I shall not stop you. If something is annoying in this world its those people like you who just cant bother to ask questions and follow everything they are told, how ever in life can you improve things that way? You think I do everything i'm told? Its people who are too right to learn that bother me. Also since you talk about programming practices you made a function that just wastes space, in the post before All that code you wrote is useless and not needed, just as i said makes a pasta you don’t need and which confuses things. Global $my_array = 0 $my_array = setArray(5) _ArrayDisplay($my_array) Func setArray($size) if ($size <= 0) Then Return 0 EndIf Local $array[$size] Return $array EndFunc ;==>setArray could replace it with just redim You really missed the point there. It is obvious you have not studied things like Strings in the C++ STL, Java's implementation of a Vector or even written a ADT yourself. I could have used ReDim, but I was trying to show you abstraction. My mistake. Turn off warnings in scite, do what you want, I don't care but you won't get far past AutoIt with your current coding views. You don't have to listen to me, read Melb23, Matt's and MvGulik post, look at some of Valik's, SmOke_N's and Jos' code and you will see some patterns. But it seems you know more then them. Post #16 is classic! lol @ retards comment there, tbh i was wondering what the hell is Dim good for If you think we are retards leave. Edited January 13, 2011 by bo8ster Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
marko29 Posted January 14, 2011 Author Share Posted January 14, 2011 Wow you really missed the point, hope I didn't mess up your hair. (someone will get that)You can get away with crap like that in AutoIt but not c/++ or Java. I guess you have never worked in a team env on enterprise code. Btw, C++ header is not a script, usually contains a class. Have you seen a C header? Where you tought global vars are best practice? And you are telling me i misunderstand things, read what i said about c++ and autoit again then rethink it few times, seems once is not enough for you.want a t-shirt? You can code any way you wish, I shall not stop you.No, i just dont need you to tell me if my code is readable because you have no idea how it looks like You think I do everything i'm told? Its people who are too right to learn that bother me. Yes i do think that, you sound like someone who cant think far enough, i ll stop here...You really missed the point there. It is obvious you have not studied things like Strings in the C++ STL, Java's implementation of a Vector or even written a ADT yourself. I could have used ReDim, but I was trying to show you abstraction. My mistake.So by abstraction you mean showing me how to waste 20 lines of code by writting redundant function that doesnt solve or help anything except wastes space?, if thats your abstraction i wonder what does your concretism look likeTurn off warnings in scite, do what you want, I don't care but you won't get far past AutoIt with your current coding views. You don't have to listen to me, read Melb23, Matt's and MvGulik post, look at some of Valik's, SmOke_N's and Jos' code and you will see some patterns. But it seems you know more then them. Neither you understand what i wrote, neither you listen. I don't need your advice, i think what i need from you is nothing, so would you just go away? Btw dont compare yourself to Melb23(or Mat, or anyone else for example) as i think he sounds and thinks totally different then youPost #16 is classic! If you think we are retards leave.I was commenting on the admins "DIm quote" and i didnt call anyone retard, read what Mel23 posted. It seems you really get things slow or just dont pay attention enough, no other explanations. And please dont post at all anymore as i wont bother to read your nonsense or reply to you, i think this went on enough offtopic and i ll end it here. Link to comment Share on other sites More sharing options...
bo8ster Posted January 14, 2011 Share Posted January 14, 2011 Yes I was wrong about the retard comment, i'll admit that and apologise. I hope you read the entire thread though. I'm not going to do a point by point, sounds like know what to do. 1. Declare global anywhere, including within functions 2. ReDim anywhere as you see fit. 3. Ignore warnings from Scite because they are not annoying. 4. Don't use Au3Check because it gives you annoying warnings. Think that sums it up, good luck with it. I'm done. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] 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