Jump to content

Bug-Report for AutoIt3 Syntax Checker v3.3.10.2


Guest
 Share

Recommended Posts

Hello,

When you check this code:

Vars()

If $var Then MsgBox(0,"",$var)


Func Vars()
    Global $var
EndFunc

with AutoIt3 Syntax Checker v3.3.10.2 then you will get this result:

 

AutoIt3 Syntax Checker v3.3.10.2  Copyright © 2007-2013 Tylo & AutoIt Team

"D:path-removedtest.au3"(3,9) : warning: $var: possibly used before declaration.
If $var Then
~~~~~~~~^
D:path-removedtest.au3 - 0 error(s), 1 warning(s)

test.au3 -> Exit Code: 1    (Runtime: 1.35 sec)

 

This is not true because $var will always be declared before line 3 because you always call to Vars() before which always declare $var ..

I always see this kind of error in my script and I'd appreciate it if you fix this bug..

thanks

Edited by Guest
Link to comment
Share on other sites

  • Moderators

gil900,

It is not a bug - and so will not be "fixed". Declaring Global variables within functions is not good coding practice and should be avoided - declaring the variable at the start of the script removes the problem and is the recommended solution. :)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

gil900,

It is not a bug - and so will not be "fixed". Declaring Global variables within functions is not good coding practice and should be avoided - declaring the variable at the start of the script removes the problem and is the recommended solution. :)

M23

This is bug ..

For the simple reason - "possibly used before declaration." is not correct in this case.

It does not matter what you think about what is "good coding practice".
 
And I think sometimes it is better to declare variables in function...
 
Anyway, "AutoIt3 Syntax Checker" should not "recommend" (in some way) to users how to code. It should be neutral...

It does not matter whether you like it or not. the Syntax Checker should say correct facts.

in this case the Syntax Checker said incorrect fact - which means BUG

it simple

Link to comment
Share on other sites

No it is not simple.

You are mixing two things: One is the flow of the syntax check and the other is the flow while executing the script.

 

And I think sometimes it is better to declare variables in function...

Can you give us an example when there is an advantage to declare a variable in a function?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

gil900,

 

This is bug

No, it is not, as I have already told you. :)

Remember that the various checking utilities are relatively simple and so cannot cover every eventuality. If you really want to declare your variables within functions but do not want to see the error then do not use Au3Check - add #AutoIt3Wrapper_Run_AU3Check=n at the top of your script and you can do whayever you want. ;)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Possible bug with something here though maybe.

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=n

Vars()

If $var Then MsgBox(0, "", $var)


Func Vars()
    Global $var
EndFunc   ;==>Vars

Treating warning like error?

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

No it is not simple.

You are mixing two things: One is the flow of the syntax check and the other is the flow while executing the script.

Can you give us an example when there is an advantage to declare a variable in a function?

 

When you use a function that is designed to run as part of the main loop and this function requires global variables to work which used only by the function and you do not always need to call this function..

for example:

#AutoIt3Wrapper_Res_File_Add=Silent.wav, sound, Silent
#AutoIt3Wrapper_Res_File_Add=1.wav, sound, sound1
#AutoIt3Wrapper_Res_File_Add=2.wav, sound, sound2
#AutoIt3Wrapper_Res_File_Add=3.wav, sound, sound3

;#AutoIt3Wrapper_Run_AU3Check=n

#include <Resources.au3>

If Not @Compiled Then
    MsgBox(16,"Error","You must to compile the script")
    Exit
EndIf

For $a = 1 To 2
    PlaySoundGroup("sound1|sound2|sound3")
    Do
        $PlaySoundGroup = PlaySoundGroup()
        Sleep(50)
    Until $PlaySoundGroup = 0
Next


Func PlaySoundGroup($Sounds = "")
    If $Sounds <> "" Then
        Global $PSG_aSounds = StringSplit($Sounds,"|",1) , $PSG_SoundPlaying = 1 ,  $PSG_StartPlay = 1 , $PSG_SoundFinish = 0
    Else
        If $PSG_SoundFinish = 0 Then
            If $PSG_StartPlay = 1 Then
                _ResourcePlaySound($PSG_aSounds[$PSG_SoundPlaying], 1)
                $PSG_StartPlay = 0
            Else
                If _ResourcePlaySound("Silent", BitOr($SND_RESOURCE, $SND_ASYNC, $SND_NOSTOP)) Then
                    If $PSG_SoundPlaying+1 > $PSG_aSounds[0] Then
                        $PSG_SoundFinish = 1
                    Else
                        $PSG_SoundPlaying = $PSG_SoundPlaying+1
                        $PSG_StartPlay = 1
                    EndIf
                EndIf
            EndIf
            Return 1
        Else
            Return 0
        EndIf
    EndIf
EndFunc

This(^) is look better then

#AutoIt3Wrapper_Res_File_Add=Silent.wav, sound, Silent
#AutoIt3Wrapper_Res_File_Add=1.wav, sound, sound1
#AutoIt3Wrapper_Res_File_Add=2.wav, sound, sound2
#AutoIt3Wrapper_Res_File_Add=3.wav, sound, sound3

;#AutoIt3Wrapper_Run_AU3Check=n

#include <Resources.au3>

If Not @Compiled Then
    MsgBox(16,"Error","You must to compile the script")
    Exit
EndIf

For $a = 1 To 2
    Global $PSG_aSounds = StringSplit("sound1|sound2|sound3","|",1) , $PSG_SoundPlaying = 1 ,  $PSG_StartPlay = 1 , $PSG_SoundFinish = 0
    Do
        $PlaySoundGroup = PlaySoundGroup()
        Sleep(50)
    Until $PlaySoundGroup = 0
Next


Func PlaySoundGroup($Sounds = "")
    If $PSG_SoundFinish = 0 Then
        If $PSG_StartPlay = 1 Then
            _ResourcePlaySound($PSG_aSounds[$PSG_SoundPlaying], 1)
            $PSG_StartPlay = 0
        Else
            If _ResourcePlaySound("Silent", BitOr($SND_RESOURCE, $SND_ASYNC, $SND_NOSTOP)) Then
                If $PSG_SoundPlaying+1 > $PSG_aSounds[0] Then
                    $PSG_SoundFinish = 1
                Else
                    $PSG_SoundPlaying = $PSG_SoundPlaying+1
                    $PSG_StartPlay = 1
                EndIf
            EndIf
        EndIf
        Return 1
    Else
        Return 0
    EndIf
EndFunc
Link to comment
Share on other sites

  • Moderators

JohnOne,

It does not stop for me: :)

>Running AU3Check (3.3.11.3)  from:M:\Program\AutoIt3\Beta  input:M:\Program\Au3 Scripts\fred4.au3
"M:\Program\Au3 Scripts\fred4.au3"(5,9) : warning: $var: possibly used before declaration.
If $var Then
~~~~~~~~^
M:\Program\Au3 Scripts\fred4.au3 - 0 error(s), 1 warning(s)
->11:57:11 AU3Check ended. Press F4 to jump to next error.rc:1
>Running:(3.3.11.3):M:\Program\AutoIt3\Beta\autoit3.exe "M:\Program\Au3 Scripts\fred4.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
+>11:57:12 AutoIt3.exe ended.rc:0
+>11:57:12 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.9903
What version of Au3Check are you running? :huh:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

gil900,

It is all a question of personal taste - I for one do not agree with your choice of preferred method. ;)

But this is definitely wrong - declaring variables inside a loop:

For $a = 1 To 2
    Global $PSG_aSounds = StringSplit("sound1|sound2|sound3","|",1) , $PSG_SoundPlaying = 1 ,  $PSG_StartPlay = 1 , $PSG_SoundFinish = 0
By doing this you are forcing AutoIt into checking the variable tables on each pass through the loop. For only 2 passes as here this is not a large penalty, but if the loop were to make a very large number of passes.... :whistle:

Normally when things are considered "good/bad coding practice" there is a valid reason behind it and going against the perceived wisdom is ususally the wrong choice. :)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

JohnOne,

It does not stop for me: :)

>Running AU3Check (3.3.11.3)  from:M:\Program\AutoIt3\Beta  input:M:\Program\Au3 Scripts\fred4.au3
"M:\Program\Au3 Scripts\fred4.au3"(5,9) : warning: $var: possibly used before declaration.
If $var Then
~~~~~~~~^
M:\Program\Au3 Scripts\fred4.au3 - 0 error(s), 1 warning(s)
->11:57:11 AU3Check ended. Press F4 to jump to next error.rc:1
>Running:(3.3.11.3):M:\Program\AutoIt3\Beta\autoit3.exe "M:\Program\Au3 Scripts\fred4.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
+>11:57:12 AutoIt3.exe ended.rc:0
+>11:57:12 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.9903
What version of Au3Check are you running? :huh:

M23

 

1.54.22.0 with Autoit 3.3.8.1 and 3.3.11.2 with autoit latest beta.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Melba23, I agree with you. I just wanted to say that

For $a = 1 To 2
    PlaySoundGroup("sound1|sound2|sound3")
 
Looks better than:
For $a = 1 To 2
    Global $PSG_aSounds = StringSplit("sound1|sound2|sound3","|",1) , $PSG_SoundPlaying = 1 ,  $PSG_StartPlay = 1 , $PSG_SoundFinish = 0

this is a example of reason why sometimes it is better to declare a variable in function.

That's the answer to water's question

 
Edited by Guest
Link to comment
Share on other sites

  • Moderators

gil900,

So declare the variables at the top of the script - then you do not need to declare them inside the loop or the function. Simple. :)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

gil900,

So declare the variables at the top of the script - then you do not need to declare them inside the loop or the function. Simple. :)

M23

 

But what if the code does not always use this function?

This is what which is not shown in the example.

If I choose your way - declare the variables of the function at the beginning of the script,

then sometimes these variables was declared for no reason.

These cases occur when the code not using that function.

So if you choose my method, that problem - unnecessary declared global variables would never happen.

Because these variables will be declared only when the code using the function.

Edited by Guest
Link to comment
Share on other sites

  • Moderators

gil900'.

 

sometimes these variables was declared for no reason

Please stop stating the obvious - we all understand your point, but you are in a vanishingly small minority who believe that your way is "better". Anyway I have had enough of this pointless discussion. :bye:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OK

I just gave legitimate reasons why sometimes it's better to declare variables within a function.
So even if the reason you're not going to fix the bug is because the method is not good and without legitimate reasons, I answered it and I gave legitimate reasons ..

So it should not be reason not to fix the bug
..

Link to comment
Share on other sites

When you use a function that is designed to run as part of the main loop and this function requires global variables to work which used only by the function and you do not always need to call this function..

Then define the variable as Static in your function - that is good coding practice for what you need the variable for.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Then define the variable as Static in your function - that is good coding practice for what you need the variable for.

Thanks for the suggestion.

What is the difference between Static to Global?

I heard from here that there is no difference

I want to know why it is better

 

EDIT:

 

When initializing a static variable, the initialization value is evaluated and assigned only the first time, when the variable is created. On all subsequent passes, the initializer is ignored.

 
I think I understand it.
Thank you for the suggestion!
Edited by Guest
Link to comment
Share on other sites

You can define the static variable in your function and it is not being released when the function ends. So when you call your function again the variable has still the same value like a global variable.

The static variable is only accessible inside the function.

So you get the best of Local and Global.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You can define the static variable in your function and it is not being released when the function ends. So when you call your function again the variable has still the same value like a global variable.

The static variable is only accessible inside the function.

So you get the best of Local and Global.

Okay.

This is definitely something good to know.

I have a few cases that I will use static

Thank you!

Link to comment
Share on other sites

More about Static can be found here.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...