Sign in to follow this  
Followers 0
big_daddy

Onexitfunc Problem

12 posts in this topic

Why does this work correctly:

Test()

Func Test($a=0)
    
    If $a == 0 Then MsgBox(0, "", "This does work!")
    
EndFunc

But this does not:

Opt("OnExitFunc", "Test")

Sleep(2000)

Func Test($a=0)
    
    If $a == 0 Then MsgBox(0, "", "This doesn't work!")
    
EndFunc

Share this post


Link to post
Share on other sites



As far as i know, OnAutoItExit() doesn't allow any parameters....

I understand that, but if the parameter is set within the function should it not work?

Share this post


Link to post
Share on other sites

I understand that, but if the parameter is set within the function should it not work?

If no parameters are processed then $a isn't initialised and thus will error out...

You can test this by added a Global $a = 0 statement. You will see that the error disapears.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

If no parameters are processed then $a isn't initialised and thus will error out...

You can test this by added a Global $a = 0 statement. You will see that the error disapears.

This somewhat limits your abilities when using the on exit function.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This somewhat limits your abilities when using the on exit function.

I just send it to another function... and set my parameters that way.

Edit:

If I remember correctly, Call() used to be this way also but since has changed...

Anyway, this is what I meant before the edit:

Opt('OnExitFunc', 'SetParams')

Func SetParams()
    If 1 + 1 = 2 Then Test(2)
EndFunc

Func Test($a = 0)
    MsgBox(0, '', $a)
EndFunc
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks, I'll remember that next time I run into this issue.

Share this post


Link to post
Share on other sites

Yay for dummy funcs!

Share this post


Link to post
Share on other sites

as i understand this

OnExitFunc Sets the name of the function called when AutoIt exits (default is OnAutoItExit).

it makes sure that this function is ran when autoit exits

here is a good example of its use... by greenmachine

#include <GUIConstants.au3>

$MagWidth = InputBox ("Magnify Area", "What should the WIDTH of the magnified area be?")
$MagHeight = InputBox ("Magnify Area", "What should the HEIGHT of the magnified area be?")
$MagZoom = InputBox ("Magnify Area", "What should the ZOOM of the magnified area be?", 2)

Global $SRCCOPY = 0x00CC0020
Global $dll[3], $DeskHDC, $GUIHDC

$dll[1] = DllOpen ( "user32.dll")
$dll[2] = DllOpen ( "gdi32.dll")

Global $GUI = GUICreate ("Zoom x2 Au3", $MagWidth * $MagZoom, $MagHeight * $MagZoom, _
    MouseGetPos (0), MouseGetPos (1), $WS_POPUP+$WS_BORDER, $WS_EX_TOPMOST)

GUISetState(@SW_SHOW)

Global $LastPos[2] = [0,0]

While 1
    MAG()
    $MousePos = MouseGetPos()
    If ($LastPos[0] <> $MousePos[0] Or $LastPos[1] <> $MousePos[1]) Then
        WinMove("Zoom x2 Au3", "", $MousePos[0] + $MagWidth/2 + 5, $MousePos[1])
        $LastPos[0] = $MousePos[0]
        $LastPos[1] = $MousePos[1]
    EndIf
    
    Sleep(10)
WEnd

Func MAG()
    $DeskHDC = DLLCall("user32.dll","int","GetDC","hwnd",0)
    $GUIHDC = DLLCall("user32.dll","int","GetDC","hwnd",$GUI)
    If Not @error Then
        DLLCall("gdi32.dll", "int", "StretchBlt", "int", $GUIHDC[0], "int", _
            0, "int", 0, "int", $MagWidth * $MagZoom, "int", $MagHeight * $MagZoom, "int", $DeskHDC[0], "int", _
            MouseGetPos (0) - $MagWidth/2, "int", MouseGetPos (1) - $MagHeight/2, "int", $MagWidth ,"int", $MagHeight, _
            "long", $SRCCOPY)
        DLLCall("user32.dll","int","ReleaseDC","int",$DeskHDC[0],"hwnd",0)
        DLLCall("user32.dll","int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI)
    EndIf
EndFunc

Func OnAutoItExit()
    DllClose ( $dll[1] )
    DllClose ( $dll[2] )
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

This somewhat limits your abilities when using the on exit function.

no it doesn't, the $a could just as easily been declared and set in the function as in the arguments section.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

You could do this:

Exit(1)

Func OnAutoItExit ( )

Msgbox(0,"The Exit Codes was:",@ExitCode)

EndFunc

Is that more like what you were looking for?


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Or you could use IsDeclared() to set var defaults.

If Not IsDeclared("var") Then $var = 0

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