Sign in to follow this  
Followers 0
Ármányos Kő

DIMmed variable to control something else ?

6 posts in this topic

#1 ·  Posted (edited)

Ok, I know this is newyear morning. But I already lost hours on this.

I created one window and used it. Later I created a new window for short time. They mixed up with each other somehow through their handles! (I lost hours of finding that).

Then I developed this script to show my problem to you.

Then it's hopefully your turn to tell me where did I make mistake.

I use> v3.2.2.0

Thanks....

;;;;;;;;;;;;      DIMmed variable receives value of something else??????????????

    
Dim $OtherVariable                                  ;Comment/uncomment this line to see the bug
Dim $OtherVariablePos[4]                        ;must declare to use when OtherWin is undeclared

HotKeySet("#{F12}","DoStrange")

$MainGUI = GUICreate("MAIN_GUI", 250, 250, -1,-1)               ; make a GUI to be able to poll it
GUISetState()                                           ; Show it

While 1 
    Sleep(50)
    If IsDeclared("OtherWin") Then 
        $OtherVariablePos = WinGetPos($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
        $OtherVariableState = WinGetState($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
    Else
        $OtherVariablePos[0] = "NODATA"
        $OtherVariablePos[1] = "NODATA"
        $OtherVariableState = "NODATA"
    EndIf
    $MainGUIpos = WinGetPos($MainGUI)
    $OtherVariableState = WinGetState($MainGUI)
    ToolTip("MainGUI="&$OtherVariableState&@CRLF&"x="&$MainGUIpos[0]&@CRLF&"y="&$MainGUIpos[1]&@CRLF&@CRLF& _
            "OtherWin_State="&$OtherVariableState&@CRLF&"x="&$OtherVariablePos[0]&@CRLF&"y="&$OtherVariablePos[1])
WEnd
        
        

Func DoStrange()
    GUIDelete($OtherVariable)
    MsgBox(0, "Seems strange", "When you can delete a GUI through an unknown handle")
EndFunc
Edited by Ármányos Kő

Share this post


Link to post
Share on other sites



Ok, I know this is newyear morning. But I already lost hours on this.

I created one window and used it. Later I created a new window for short time. They mixed up with each other somehow through their handles! (I lost hours of finding that).

Then I developed this script to show my problem to you.

Then it's hopefully your turn to tell me where did I make mistake.

I use> v3.2.2.0

Thanks....

;;;;;;;;;;;;      DIMmed variable receives value of something else??????????????

    
Dim $OtherVariable                              ;Comment/uncomment this line to see the bug
Dim $OtherVariablePos[4]                    ;must declare to use when OtherWin is undeclared

HotKeySet("#{F12}","DoStrange")

$MainGUI = GUICreate("MAIN_GUI", 250, 250, -1,-1)           ; make a GUI to be able to poll it
GUISetState()                                       ; Show it

While 1 
    Sleep(50)
    If IsDeclared("OtherWin") Then 
        $OtherVariablePos = WinGetPos($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
        $OtherVariableState = WinGetState($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
    Else
        $OtherVariablePos[0] = "NODATA"
        $OtherVariablePos[1] = "NODATA"
        $OtherVariableState = "NODATA"
    EndIf
    $MainGUIpos = WinGetPos($MainGUI)
    $OtherVariableState = WinGetState($MainGUI)
    ToolTip("MainGUI="&$OtherVariableState&@CRLF&"x="&$MainGUIpos[0]&@CRLF&"y="&$MainGUIpos[1]&@CRLF&@CRLF& _
            "OtherWin_State="&$OtherVariableState&@CRLF&"x="&$OtherVariablePos[0]&@CRLF&"y="&$OtherVariablePos[1])
WEnd
        
        

Func DoStrange()
    GUIDelete($OtherVariable)
    MsgBox(0, "Seems strange", "When you can delete a GUI through an unknown handle")
EndFunc
I don't think it's a bug. I think it's because AutoIt variables are variants. In WingetPos the parameter is interpreted as a string, so I think the variable without a value is interpreted as being the same as ''. This is then taken to be the most recently active window which presumably will be the one you just created.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok, I know this is newyear morning. But I already lost hours on this.

I created one window and used it. Later I created a new window for short time. They mixed up with each other somehow through their handles! (I lost hours of finding that).

Then I developed this script to show my problem to you.

Then it's hopefully your turn to tell me where did I make mistake.

I use> v3.2.2.0

Thanks....

Current production version is 3.2.10.0. Why are you on such an old version...? :)

I'm not going to reload the old version, but with 3.2.10.0 it behaves exactly as expected. Even with your DIM uncommented, you never set $OtherVariable to anything, so it is null. A null window title parameter means "currently active window" for all the Win* functions and "last used" for Gui* functions. When the DIM line is commented out, it fails AU3Check, and if you continue to run it despite that, it crashes.

Here's the version I ran (cleaned up to include a way to exit):

;;;;;;;;;;;;      DIMmed variable receives value of something else??????????????

Dim $OtherVariable                                    ;Comment/uncomment this line to see the bug
Dim $OtherVariablePos[4]                        ;must declare to use when OtherWin is undeclared

HotKeySet("#{F12}", "DoStrange")
HotKeySet("{ESC}", "_Quit")

$MainGUI = GUICreate("MAIN_GUI", 250, 250, -1, -1)                ; make a GUI to be able to poll it
GUISetState()                                            ; Show it

While 1
    Sleep(50)
    If IsDeclared("OtherWin") Then
        $OtherVariablePos = WinGetPos($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
        $OtherVariableState = WinGetState($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
    Else
        $OtherVariablePos[0] = "NODATA"
        $OtherVariablePos[1] = "NODATA"
        $OtherVariableState = "NODATA"
    EndIf
    $MainGUIpos = WinGetPos($MainGUI)
    $OtherVariableState = WinGetState($MainGUI)
    ToolTip("MainGUI=" & $OtherVariableState & @CRLF & "x=" & $MainGUIpos[0] & @CRLF & "y=" & $MainGUIpos[1] & @CRLF & @CRLF & _
            "OtherWin_State=" & $OtherVariableState & @CRLF & "x=" & $OtherVariablePos[0] & @CRLF & "y=" & $OtherVariablePos[1])
WEnd

Func DoStrange()
    ConsoleWrite("Debug: WinGetTitle(" & $OtherVariable & ") = " & WinGetTitle($OtherVariable) & @LF)
EndFunc   ;==>DoStrange

Func _Quit()
    Exit
EndFunc

And here's the output from it:

+>11:52:22 Starting AutoIt3Wrapper v.1.9.4
>Running AU3Check (1.54.10.0)  from:C:\Program Files\AutoIt3
+>11:52:22 AU3Check ended.rc:0
>Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3"  
Debug: WinGetTitle() = MAIN_GUI
+>11:52:33 AutoIT3.exe ended.rc:0
+>11:52:34 AutoIt3Wrapper Finished
>Exit code: 0   Time: 12.874

And here's the output of the ConsoleWrite line if I switch active windows before hitting WIN-F12:

Debug: WinGetTitle() = C:\Program Files\AutoIt3\Scripts\Test_1.au3 - SciTE [2 of 2]

Exactly as expected for null window title parameter. If I comment out the line for DIM $OtherVariable, it fails AU3Check, and then crashes when I hit WIN-F12, as expected because nothing else creates the variable:

+>11:57:37 Starting AutoIt3Wrapper v.1.9.4
>Running AU3Check (1.54.10.0)  from:C:\Program Files\AutoIt3
C:\Program Files\AutoIt3\Scripts\Test_1.au3(15,47) : WARNING: $OtherVariable: possibly used before declaration.
        $OtherVariablePos = WinGetPos($OtherVariable)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Scripts\Test_1.au3(15,47) : ERROR: $OtherVariable: undeclared global variable.
        $OtherVariablePos = WinGetPos($OtherVariable)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Scripts\Test_1.au3 - 1 error(s), 1 warning(s)
!>11:57:37 AU3Check ended.rc:2
>Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3"  
C:\Program Files\AutoIt3\Scripts\Test_1.au3 (29) : ==> Variable used without being declared.: 
ConsoleWrite("Debug: WinGetTitle(" & $OtherVariable & ") = " & WinGetTitle($OtherVariable) & @LF) 
ConsoleWrite("Debug: WinGetTitle(" & ^ ERROR
->11:57:46 AutoIT3.exe ended.rc:1
+>11:57:46 AutoIt3Wrapper Finished
>Exit code: 1   Time: 9.880

Where's the bug?

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Current production version is 3.2.10.0. Why are you on such an old version...? :)

I'm not going to reload the old version, but with 3.2.10.0 it behaves exactly as expected. Even with your DIM uncommented, you never set $OtherVariable to anything, so it is null. A null window title parameter means "currently active window" for all the Win* functions and "last used" for Gui* functions. When the DIM line is commented out, it fails AU3Check, and if you continue to run it despite that, it crashes.

Here's the version I ran (cleaned up to include a way to exit):

;;;;;;;;;;;;      DIMmed variable receives value of something else??????????????

Dim $OtherVariable                                    ;Comment/uncomment this line to see the bug
Dim $OtherVariablePos[4]                        ;must declare to use when OtherWin is undeclared

HotKeySet("#{F12}", "DoStrange")
HotKeySet("{ESC}", "_Quit")

$MainGUI = GUICreate("MAIN_GUI", 250, 250, -1, -1)                ; make a GUI to be able to poll it
GUISetState()                                            ; Show it

While 1
    Sleep(50)
    If IsDeclared("OtherWin") Then
        $OtherVariablePos = WinGetPos($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
        $OtherVariableState = WinGetState($OtherVariable); BUG?   This assigns value to the non-existing $OtherVariable
    Else
        $OtherVariablePos[0] = "NODATA"
        $OtherVariablePos[1] = "NODATA"
        $OtherVariableState = "NODATA"
    EndIf
    $MainGUIpos = WinGetPos($MainGUI)
    $OtherVariableState = WinGetState($MainGUI)
    ToolTip("MainGUI=" & $OtherVariableState & @CRLF & "x=" & $MainGUIpos[0] & @CRLF & "y=" & $MainGUIpos[1] & @CRLF & @CRLF & _
            "OtherWin_State=" & $OtherVariableState & @CRLF & "x=" & $OtherVariablePos[0] & @CRLF & "y=" & $OtherVariablePos[1])
WEnd

Func DoStrange()
    ConsoleWrite("Debug: WinGetTitle(" & $OtherVariable & ") = " & WinGetTitle($OtherVariable) & @LF)
EndFunc   ;==>DoStrange

Func _Quit()
    Exit
EndFunc

And here's the output from it:

+>11:52:22 Starting AutoIt3Wrapper v.1.9.4
>Running AU3Check (1.54.10.0)  from:C:\Program Files\AutoIt3
+>11:52:22 AU3Check ended.rc:0
>Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3"  
Debug: WinGetTitle() = MAIN_GUI
+>11:52:33 AutoIT3.exe ended.rc:0
+>11:52:34 AutoIt3Wrapper Finished
>Exit code: 0   Time: 12.874

And here's the output of the ConsoleWrite line if I switch active windows before hitting WIN-F12:

Debug: WinGetTitle() = C:\Program Files\AutoIt3\Scripts\Test_1.au3 - SciTE [2 of 2]

Exactly as expected for null window title parameter. If I comment out the line for DIM $OtherVariable, it fails AU3Check, and then crashes when I hit WIN-F12, as expected because nothing else creates the variable:

+>11:57:37 Starting AutoIt3Wrapper v.1.9.4
>Running AU3Check (1.54.10.0)  from:C:\Program Files\AutoIt3
C:\Program Files\AutoIt3\Scripts\Test_1.au3(15,47) : WARNING: $OtherVariable: possibly used before declaration.
        $OtherVariablePos = WinGetPos($OtherVariable)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Scripts\Test_1.au3(15,47) : ERROR: $OtherVariable: undeclared global variable.
        $OtherVariablePos = WinGetPos($OtherVariable)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Scripts\Test_1.au3 - 1 error(s), 1 warning(s)
!>11:57:37 AU3Check ended.rc:2
>Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3"  
C:\Program Files\AutoIt3\Scripts\Test_1.au3 (29) : ==> Variable used without being declared.: 
ConsoleWrite("Debug: WinGetTitle(" & $OtherVariable & ") = " & WinGetTitle($OtherVariable) & @LF) 
ConsoleWrite("Debug: WinGetTitle(" & ^ ERROR
->11:57:46 AutoIT3.exe ended.rc:1
+>11:57:46 AutoIt3Wrapper Finished
>Exit code: 1   Time: 9.880

Where's the bug?

:P

Thanks Guys!

Basically I also think this comes from the $OtherVariable being "".

But somehow I was totally misled by this comment in the Helpfile>

Note: Window handles will work no matter what WinTitleMatchMode is currently in use. (From the bottom of the "Window Titles and Text (Advanced)" page.) This actually tells that if you use handles in WinGetPos argument, you will get good results. For this reason I suggest to insert an additional comment like this>

"Note: Window handles will work no matter what WinTitleMatchMode is currently in use. However if you use a handle which is not previously assigned to a GUI or to some other value, you will get results from the last used GUI."

Or maybe this can be recognised by AU3Check.

I am not upgraded to 3.2.10 yet because of several issues. But will do right now.

Thanks!

Share this post


Link to post
Share on other sites

Thanks Guys!

Basically I also think this comes from the $OtherVariable being "".

But somehow I was totally misled by this comment in the Helpfile>

Note: Window handles will work no matter what WinTitleMatchMode is currently in use. (From the bottom of the "Window Titles and Text (Advanced)" page.) This actually tells that if you use handles in WinGetPos argument, you will get good results. For this reason I suggest to insert an additional comment like this>

"Note: Window handles will work no matter what WinTitleMatchMode is currently in use. However if you use a handle which is not previously assigned to a GUI or to some other value, you will get results from the last used GUI."

Or maybe this can be recognised by AU3Check.

I am not upgraded to 3.2.10 yet because of several issues. But will do right now.

Thanks!

I see how that gets confusing.

All AutoIt variables are type Variant. Though there is some internal flagging of the type behind the curtain , the Wizard has his own rules on automatic conversion of types, etc. You can use VarGetType to see how the AutoIt interpreter currently has that variable flagged, but that flag is dynamic and the same variable chages types based on what's put in it.

When you declared $OtherVariable is had no type assigned, it was just a null value with a default type of "String". So what you passed was not a handle at all. The text you quoted only comes into play for a variable that actually has a handle in it.

Dim $OtherVariable 
ConsoleWrite("Debug VarGetType($OtherVariable) = " & VarGetType($OtherVariable) & " = " & $OtherVariable & @LF)

$OtherVariable = MouseGetPos()
ConsoleWrite("Debug VarGetType($OtherVariable) = " & VarGetType($OtherVariable) & " = [" & $OtherVariable[0] & _
        "][" & $OtherVariable[1] & "]" & @LF)

$OtherVariable = WinGetHandle("")
ConsoleWrite("Debug VarGetType($OtherVariable) = " & VarGetType($OtherVariable) & " = " & $OtherVariable & @LF)

$OtherVariable = Sqrt(4)
ConsoleWrite("Debug VarGetType($OtherVariable) = " & VarGetType($OtherVariable) & " = " & $OtherVariable & @LF)

$OtherVariable = Sqrt(2) ; Hmm... expected Float, got Double
ConsoleWrite("Debug VarGetType($OtherVariable) = " & VarGetType($OtherVariable) & " = " & $OtherVariable & @LF)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I see how that gets confusing.

All AutoIt variables are type Variant. Though there is some internal flagging of the type behind the curtain , the Wizard has his own rules on automatic conversion of types, etc. You can use VarGetType to see how the AutoIt interpreter currently has that variable flagged, but that flag is dynamic and the same variable chages types based on what's put in it.

When you declared $OtherVariable is had no type assigned, it was just a null value with a default type of "String". So what you passed was not a handle at all. The text you quoted only comes into play for a variable that actually has a handle in it.

:)

Anyway, I placed my second window generation onto the top of the file with a big SW_HIDE at the end.

Then use SW_SHOW when it is needed.

Thanks!

Share this post


Link to post
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
Sign in to follow this  
Followers 0