Jump to content

Recommended Posts

Posted (edited)
Using this script you can analyze the old scripts and search for keywords like:
Local Global Dim Static
 
Search only the above keywords used inside the Loop statements like:
 
For ... Next
While ... Wend
Do ... Until
For ... In ... Next
 

 

This script parses a other script and reports on incorrect variable declarations within loops.

Remark: Variable declaration is needed but it should be done outside the loop.

 
 
Basic information of this script:
 
Currently, the script provides two functions:
_Check_Local_In_Loop__File()
_Check_Local_In_Loop__Folder ()
 
Using functions: _Check_Local_In_Loop__File()
You can specify a single file *. Au3
file will be checked for using the keyword "Local" inside the Loop Statements
According to the used parameters the result will be send to SciTE console,  Clipboard, eventualy displayed using _ArrayDisplay().
 
 
Using functions: _Check_Local_In_Loop__Folder ()
You can specify the folder containing the files *. Au3
All files in the given directory will be subject to analysis like above.
 
 
The use of parameters, the internal functions:
_Check_Local_In_Loop_Check_File ($ HFile, $ fArrayDisplay = True)
additionally determines the manner of presenting the results of the work of this script.


First Version 2013/12/03 02:00 AM

  Reveal hidden contents



 
EXAMPLE 1:
Run that script in Current Beta: AutoIt 3.3.9.23  
select Au3 file for example: array.au3 (from include AutoIt 3.3.9.23)
results:
Row  |Col 0
0|While 1
 
1|Local $aiCurItems[1] = [0]
 
2|Local $aiCurItems[1] = [0]
 

Explanation:
Open this file in SciTE.exe and search text:
Local $aiCurItems[1] = [0]
You'll notice that this text is inside:
While 1
 



 
EXAMPLE 2:
Run that script in Current Beta: AutoIt 3.3.9.23  
select Au3 file for example: ie.au3 (from include AutoIt 3.3.9.23)
results:
Row  |Col 0
0|For $o_window In $o_ShellWindows
 
1|Local $f_found = False
 
2|Local $f_found = False
 

Explanation:
Open this file in SciTE.exe and search text:
Local $f_found = False
You'll notice that this text is inside:
For $o_window In $o_ShellWindows
 



 
EXAMPLE 3: 
Run that script in Current Beta: AutoIt 3.3.9.23  
select Au3 file for example: GuiListView.au3  (from include AutoIt 3.3.9.23)
results:
Row  |Col 0
0|For $i = 0 To $items - 1
 
1|Local $a_indices[2]
 
2|Local $a_indices[2]
 

Explanation:
Open this file in SciTE.exe and search text:
Local $a_indices[2]
You'll notice that this text is inside:
For $i = 0 To $items - 1
 



 
EXAMPLE 4:
Run that script in Current Beta: AutoIt 3.3.9.23  
select Au3 file for example: array.au3  (from include AutoIt 3.3.8.1)
results:
Row  |Col 0
0|While 1
 
1|Local $sClip = ""
Local $aiCurItems[1] = [0]
 
2|Local $aiCurItems[1] = [0]
 
 
 

 
Row  |Col 0
0|For $x = 1 To 255
 
1|Local $sFind = _ArraySearch($avArray, Chr($x), 0, 0, 0, 1)
 
2|Local $sFind = _ArraySearch($avArray, Chr($x), 0, 0, 0, 1)

Explanation:
Open this file in SciTE.exe and
 
search text:
Local $sClip = ""
Local $aiCurItems[1] = [0]
You'll notice that this text is inside:
While 1
 
 
search text:
Local $sFind = _ArraySearch($avArray, Chr($x), 0, 0, 0, 1)
You'll notice that this text is inside:
For $x = 1 To 255



Version 2013/12/03 05:34 PM

  • _Check_Local_In_Loop__Folder()    ---> FileSelectFolder ()
  • parameter $fArrayDisplay = True
  • parameter $fReturnAsString = False

  Reveal hidden contents

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#AutoIt3Wrapper_Version=B
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <array.au3>



;~ _Check_Local_In_Loop()
_Check_Local_In_Loop__Folder()

Func _Check_Local_In_Loop()
    Local $hFile = FileOpenDialog('Select Au3 file to check', @ScriptDir, 'AutoIt3 Files (*.au3)', $FD_FILEMUSTEXIST)
    _Check_Local_In_Loop_Check_File($hFile)
EndFunc ;==>_Check_Local_In_Loop

Func _Check_Local_In_Loop__Folder()
    Local $hFile = FileSelectFolder('Select folder with Au3 file to check', '', 4)
    Local $aAu3Files = _FileListToArray($hFile, '*.au3', 1, True)
    Local $sTextTemp = ''
    Local $sTextOut = ''
    For $File In $aAu3Files
        $sTextTemp = _Check_Local_In_Loop_Check_File($File, False, True)
        If $sTextTemp <> '' Then
            $sTextOut &= '======================================================' & @CRLF
            $sTextOut &= $File & @CRLF
            $sTextOut &= '======================================================' & @CRLF
            $sTextOut &= $sTextTemp
            $sTextOut &= '------------------------------------------------------' & @CRLF
        EndIf
    Next
    ClipPut($sTextOut)
    MsgBox(1, 'Result', $sTextOut)
EndFunc ;==>_Check_Local_In_Loop__Folder

Func _Check_Local_In_Loop_Check_File($hFile, $fArrayDisplay = True, $fReturnAsString = False)
    Local $sFileContent = FileRead($hFile)
    Local $sFileName = StringRegExpReplace($hFile, '.*', '')


    Local $sTextToFind = _Local_inside_Loop($sFileContent)
    Local $fContinue_EndFunc, $fContinue_Local, $fContinue_Wend, $fContinue_Until, $fContinue_Next
    Do
        ConsoleWrite(@CRLF)
        $fContinue_EndFunc = _Remove_Func_EndFunc($sTextToFind)
        $fContinue_Local = _Remove_Func_Local($sTextToFind)
        $fContinue_Wend = _Remove_While_Wend($sTextToFind)
        $fContinue_Until = _Remove_DO_UNTIL($sTextToFind)
        $fContinue_Next = _Remove_For_Next($sTextToFind)
    Until $fContinue_EndFunc = False And $fContinue_Local = False And $fContinue_Wend = False And $fContinue_Until = False And $fContinue_Next = False
;~     ClipPut($sTextToFind)
;~     MsgBox(1, 'Result', $sTextToFind)
    Local $sREGEXP = '', $sTextOut = ''


    $sREGEXP = '(?i)(While .*rn)((Local .*rn)+)()'
    Local $aWhileWend = StringRegExp($sTextToFind, $sREGEXP, 3)
    If $fArrayDisplay = True Then _ArrayDisplay($aWhileWend, '$aWhileWend , $sFileName: ' & $sFileName)
    If $fReturnAsString = True Then $sTextOut &= _ArrayToString($aWhileWend, @CRLF)

    $sREGEXP = '(?i)(Dorn|Do ;V*rn)((Local .*rn)+)()'
    Local $aDoUntil = StringRegExp($sTextToFind, $sREGEXP, 3)
    If $fArrayDisplay = True Then _ArrayDisplay($aDoUntil, '$aDoUntil , $sFileName: ' & $sFileName)
    If $fReturnAsString = True Then $sTextOut &= _ArrayToString($aDoUntil, @CRLF)

    $sREGEXP = '(?i)(For .*rn)((Local .*rn)+)()'
    Local $aForNext = StringRegExp($sTextToFind, $sREGEXP, 3)
    If $fArrayDisplay = True Then _ArrayDisplay($aForNext, '$aForNext , $sFileName: ' & $sFileName)
    If $fReturnAsString = True Then $sTextOut &= _ArrayToString($aForNext, @CRLF)

    Return SetError(1, 0, $sTextOut)
EndFunc ;==>_Check_Local_In_Loop_Check_File

Func _Local_inside_Loop($sTEXT)
    Local $sREGEXP = '(?is)(?<=rn)(?:s*?)(Func V*|EndFuncV*|While V*|WendV*|Do(?=rn)|Do ;V*|Until V*|For V*|NextV*|Local V*)'
    Local $aTEXT = StringRegExp($sTEXT, $sREGEXP, 3)
    Return _ArrayToString($aTEXT, @CRLF)
EndFunc ;==>_Local_inside_Loop

Func _Remove_Func_EndFunc(ByRef $sText)
    Local $fReturn_IsNotComplex = True
    Local $sREGEXP = '(?i)(Func V*rn)(EndFuncV*rn)'
    $sText = StringRegExpReplace($sText, $sREGEXP, '')
    If @error = 0 And @extended = 0 Then $fReturn_IsNotComplex = False
    ConsoleWrite('_Remove_Func_EndFunc $fReturn_IsNotComplex = ' & $fReturn_IsNotComplex & @CRLF)
    Return $fReturn_IsNotComplex
EndFunc ;==>_Remove_Func_EndFunc

Func _Remove_Func_Local(ByRef $sText)
    Local $fReturn_IsNotComplex = True
    Local $sREGEXP = '(?i)(Func .*rn)((Local .*rn)+)'
    $sText = StringRegExpReplace($sText, $sREGEXP, '$1')
    If @error = 0 And @extended = 0 Then $fReturn_IsNotComplex = False
    ConsoleWrite('_Remove_Func_Local $fReturn_IsNotComplex = ' & $fReturn_IsNotComplex & @CRLF)
    Return $fReturn_IsNotComplex
EndFunc ;==>_Remove_Func_Local

Func _Remove_While_Wend(ByRef $sText)
    Local $fReturn_IsNotComplex = True
    Local $sREGEXP = '(?i)(While V*rn)(WendV*rn)'
    $sText = StringRegExpReplace($sText, $sREGEXP, '')
    If @error = 0 And @extended = 0 Then $fReturn_IsNotComplex = False
    ConsoleWrite('_Remove_While_Wend $fReturn_IsNotComplex = ' & $fReturn_IsNotComplex & @CRLF)
    Return $fReturn_IsNotComplex
EndFunc ;==>_Remove_While_Wend

Func _Remove_DO_UNTIL(ByRef $sText)
    Local $fReturn_IsNotComplex = True
    Local $sREGEXP = '(?i)(Dorn|Do ;V*rn)(Until V*rn)'
    $sText = StringRegExpReplace($sText, $sREGEXP, '')
    If @error = 0 And @extended = 0 Then $fReturn_IsNotComplex = False
    ConsoleWrite('_Remove_DO_UNTIL $fReturn_IsNotComplex = ' & $fReturn_IsNotComplex & @CRLF)
    Return $fReturn_IsNotComplex
EndFunc ;==>_Remove_DO_UNTIL

Func _Remove_For_Next(ByRef $sText)
    Local $fReturn_IsNotComplex = True
    Local $sREGEXP = '(?i)(For V*rn)(NextV*rn)'
    $sText = StringRegExpReplace($sText, $sREGEXP, '')
    If @error = 0 And @extended = 0 Then $fReturn_IsNotComplex = False
    ConsoleWrite('_Remove_For_Next $fReturn_IsNotComplex = ' & $fReturn_IsNotComplex & @CRLF)
    Return $fReturn_IsNotComplex
EndFunc ;==>_Remove_For_Next
 

 

 

Version 2013/12/04 01:42 AM

  • removed parameter $fReturnAsString
  • added output to SciTE console
  • removed not needed info from SciTE console
  • Fixed problem with Loop statements on the begining of script
  • added option (MsgBox) to choose    "File or Folder"
  • added option (MsgBox) to choose   "Open file"

see attached au3 file


!!! NEW Version 2013/12/05 01:40 AM

  • added checking for Global Dim and Static
  • some other modyfication in REGEXP  pattern

see attached: BestCodingPractice_Analyzer__Version_20131205_0140_AM.zip

 

BestCodingPractice_Analyzer.au3

BestCodingPractice_Analyzer__Version_20131205_0140_AM.zip

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Not at all. But partially yes :)

EDIT: spelling

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi Mlipok,

             Nice Idea. may i know from where i can download MsgBoxConstants.au3 file?

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Posted

  On 12/3/2013 at 11:34 AM, Syed23 said:

Hi Mlipok,

 

             Nice Idea. may i know from where i can download MsgBoxConstants.au3 file?

 

yes of course

http://www.autoitscript.com/forum/files/file/267-autoit-v33923-beta/

HINT: you must install and in SciTE use ALT+F5 or ALT+F7

 

ps.

I'm glad you like it

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

Syed23,

If you do not want to install the Beta, just use Constants.au3 with 3.3.8.1. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

Posted

Thank you so much Melba23 that worked very well.

Milpok i tried with Melba23 idea and the code works very nice... this is really good... 

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Posted

!!! NEW Version 2013/12/03 05:34 PM

  • _Check_Local_In_Loop__Folder()    ---> FileSelectFolder ()
  • parameter $fArrayDisplay = True
  • parameter $fReturnAsString = False

 

Please check in the opening post.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Please don't use spoiler tags, just upload the file instead as I am confused as to which one I should use. Anyway, I ran your code with this and if reported nothing in the console.

While 1
    Local $fTest = True
    ConsoleWrite($fTest & @CRLF)
WEnd

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)
  On 12/3/2013 at 9:01 PM, guinness said:

 

Please don't use spoiler tags, just upload the file instead as I am confused as to which one I should use. Anyway, I ran your code with this and if reported nothing in the console.

While 1
    Local $fTest = True
    ConsoleWrite($fTest & @CRLF)
WEnd

 

Did you expect the result to the console.

Currently, the program displays the MsgBox and sends the results to the clipboard.
 
If you think that the option with the console is more preferred, of course, it will introduce.
The more that I'm working on further amendments.
 
 
Referring to the example:
;add any line before loop statement
While 1
    Local $fTest = True
    ConsoleWrite($fTest & @CRLF)
WEnd

I think it's quite logical that, in most cases, the script does not begin by calling the loop.

 

edit:

'Please don't use spoiler tags, just upload the file instead"

Ok I change this at the next opportunity / amendment.

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Who is to say what's logical about just jumping straight to a loop? There's nothing to prevent it, or anything that would say it's wrong to do it. Your script should recognize this.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

I think I need clearer instructions on how to use then, because I just tried with your second spoiler tag code and it produced a message box with no data and this in the console. The clipboard was also empty. I chose the desktop where my test Au3 Script from above was present.

_Remove_Func_EndFunc $fReturn_IsNotComplex = False
_Remove_Func_Local $fReturn_IsNotComplex = False
_Remove_While_Wend $fReturn_IsNotComplex = False
_Remove_DO_UNTIL $fReturn_IsNotComplex = False
_Remove_For_Next $fReturn_IsNotComplex = False

_Remove_Func_EndFunc $fReturn_IsNotComplex = True
_Remove_Func_Local $fReturn_IsNotComplex = True
_Remove_While_Wend $fReturn_IsNotComplex = False
_Remove_DO_UNTIL $fReturn_IsNotComplex = True
_Remove_For_Next $fReturn_IsNotComplex = True

_Remove_Func_EndFunc $fReturn_IsNotComplex = True
_Remove_Func_Local $fReturn_IsNotComplex = False
_Remove_While_Wend $fReturn_IsNotComplex = False
_Remove_DO_UNTIL $fReturn_IsNotComplex = False
_Remove_For_Next $fReturn_IsNotComplex = False

_Remove_Func_EndFunc $fReturn_IsNotComplex = False
_Remove_Func_Local $fReturn_IsNotComplex = False
_Remove_While_Wend $fReturn_IsNotComplex = False
_Remove_DO_UNTIL $fReturn_IsNotComplex = False
_Remove_For_Next $fReturn_IsNotComplex = False

_Remove_Func_EndFunc $fReturn_IsNotComplex = False
_Remove_Func_Local $fReturn_IsNotComplex = False
_Remove_While_Wend $fReturn_IsNotComplex = False
_Remove_DO_UNTIL $fReturn_IsNotComplex = False
_Remove_For_Next $fReturn_IsNotComplex = False

Perhaps in your first post you should be concise as to what this analyzer does, maybe a small example of what it's expected to report to the user. 

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

In the next few hours I'll update the script and description.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 12/3/2013 at 10:33 PM, mlipok said:

In the next few hours I'll update the script and description.

Thanks.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

!!! NEW Version 2013/12/04 01:42 AM

  • removed parameter $fReturnAsString
  • added output to SciTE console
  • removed not needed info from SciTE console
  • Fixed problem with Loop statements on the begining of script
  • added option (MsgBox) to choose    "File or Folder"
  • added option (MsgBox) to choose   "Open file"

 

see attached file in opening post

btw.

I made a new entry to the description.

Tomorrow even sort out the examples and way of describing version.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 12/4/2013 at 8:36 AM, D4RKON3 said:

Am I the only one who can't see any attached file?

No, I can't either.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

I'm sorry for all concerned.
The file can be downloaded already.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Erroneous declarations are really just the tip of the iceberg. People don't always agree on what is, or isn't, good coding practice. I'm not dismissing your idea because it may have potential in terms of teaching AutoIt basics.

I also see the logic of your example: I can't think of any reason why someone would want to decalre a variable* within a loop other than to test the interpreter in some way. A  distinction should be made between that which is clearly wrong and that which is mostly a matter of opinion.

* the same variable

Edited by czardas
Posted

I always considered Tidy a best coding practice analyzer.

  Reveal hidden contents

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...