donnyh13 Posted November 15, 2023 Share Posted November 15, 2023 Hi All, I have a general question about re-declaring AutoIt Constants in a local scope. In a UDF I have created I have from time to time needed to use a flag for built-in AutoIt functions, such as StringStripWS, or UBound. Instead of using magic numbers I have vouched for using the corresponding flag, but instead of including the necessary Include, I have declared an Identically named Constant locally in the function, such as the following: func _SomeFunc($sFile) Local Const $STR_STRIPLEADING = 1 $sFile = StringStripWS($sFile, $STR_STRIPLEADING) EndFunc Is this a bad idea? I was wanting to avoid having to have a pile of Includes for the UDF if it wasn't necessary. LibreOffice UDF ; Scite4AutoIt Spell-Checker Using LibreOffice Spoiler "Life is chiefly made up, not of great sacrifices and wonderful achievements, but of little things. It is oftenest through the little things which seem so unworthy of notice that great good or evil is brought into our lives. It is through our failure to endure the tests that come to us in little things, that the habits are molded, the character misshaped; and when the greater tests come, they find us unready. Only by acting upon principle in the tests of daily life can we acquire power to stand firm and faithful in the most dangerous and most difficult positions." Link to comment Share on other sites More sharing options...
Andreik Posted November 15, 2023 Share Posted November 15, 2023 (edited) 18 minutes ago, donnyh13 said: Is this a bad idea? I was wanting to avoid having to have a pile of Includes for the UDF if it wasn't necessary. I usually do this when I use few constants but if I use more functions and constants I include the whole UDF. If this is a bad idea? It really depends. If there is a function that is called every second it's not the best way. I hope to see soon in AutoIt implemented local static constants, so we can have something like this: Func Test() Local Static Const $MB_OK = 0 ... EndFunc Edited November 15, 2023 by Andreik donnyh13 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
donnyh13 Posted November 15, 2023 Author Share Posted November 15, 2023 Thanks @Andreik, that sounds about the same as what I had in mind. Ya, a static constant would be handy in this situation. LibreOffice UDF ; Scite4AutoIt Spell-Checker Using LibreOffice Spoiler "Life is chiefly made up, not of great sacrifices and wonderful achievements, but of little things. It is oftenest through the little things which seem so unworthy of notice that great good or evil is brought into our lives. It is through our failure to endure the tests that come to us in little things, that the habits are molded, the character misshaped; and when the greater tests come, they find us unready. Only by acting upon principle in the tests of daily life can we acquire power to stand firm and faithful in the most dangerous and most difficult positions." 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