Sign in to follow this  
Followers 0
Angel

Using a function with default parameter values as an "OnEvent" function

8 posts in this topic

Hi,

I have a function with a single parameter. That parameter has a default value. Therefore it can be called without any parameters.

This made me think that I can use this function as the "OnEvent" function of one of the elements of my GUI. However, when I do that and the function is run after the corresponding event, I get an error telling me that the variable corresponding to the argument does not exist.

Is that normal or is it a bug?

Thanks!

Angel

Share this post


Link to post
Share on other sites



are you calling the funtion with "callfunction" quotes - cause if you are then your function would have to use the same amount of paramaters - and as far as I remember and have read - you would not be able to call the function with paramaters. This would be nice if you could though. what I have found is that you have to make the variables global and then change them from within the function.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

are you calling the funtion with "callfunction" quotes - cause if you are then your function would have to use the same amount of paramaters - and as far as I remember and have read - you would not be able to call the function with paramaters. This would be nice if you could though. what I have found is that you have to make the variables global and then change them from within the function.

Sorry, I don't understand what you mean by ' "callfunction" quotes '.

The function is called by autoit itself. I tell AutoIt to call it by means of GuiCtrlSetOnEvent.

I can live with this limitation but it is kind of confusing. It would seem reasonable to expect that if a function is called with no parameters, and in its definition it has parameters with default values, AutoIt would be able to call that function when an event happends, using those default parameters. That is why it felt as a bug to me.

Angel

Share this post


Link to post
Share on other sites

As you are describing the problem, everything seems fine, but we have yet to see any code. Is there a way you could provide a code snippet that would allow us to test this ourselves?

I havent had this issue before with GUICtrlSetOnEvent(). I am now using that as my standard GUI creation method.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

As you are describing the problem, everything seems fine, but we have yet to see any code. Is there a way you could provide a code snippet that would allow us to test this ourselves?

I havent had this issue before with GUICtrlSetOnEvent(). I am now using that as my standard GUI creation method.

JS

You haven't had an issue of calling a function that has a parameter with OnEventMode :whistle: ?

Edit:

Directly I mean... without an EventHandler.

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

OnEventMode does not support parameters in the called functions unless I missed a recent change.

Share this post


Link to post
Share on other sites

You haven't had an issue of calling a function that has a parameter with OnEventMode :whistle: ?

Edit:

Directly I mean... without an EventHandler.

I know it cannot be called directly, but the function in question doesnt "require" any parameter so in a technical stand point it should work, and to my knowledge has for me in the past. I dont remember having to create a work around for a "default" parameter because I didnt call it explicitly.

Please see the code example below.

GUICtrlSetOnEvent($someButton, "_SomeFunction")

Func _SomeFunction($defaultParam = "nothing")
    MsgBox(0, "Test _SomeFunction", $defaultParam)
EndFunc

The above should work because it doesnt require a parameter. I will look in my files and be sure that I have done this in the past. I am 79% certain that I have.

Thanks,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

I know it cannot be called directly, but the function in question doesnt "require" any parameter so in a technical stand point it should work, and to my knowledge has for me in the past. I dont remember having to create a work around for a "default" parameter because I didnt call it explicitly.

Please see the code example below.

GUICtrlSetOnEvent($someButton, "_SomeFunction")

Func _SomeFunction($defaultParam = "nothing")
    MsgBox(0, "Test _SomeFunction", $defaultParam)
EndFunc
oÝ÷ Ù8^/zÈhºWp¢¹yÆ®±è­v¬ÚÞªè«yªZ­©µêÈÂ)e$y²~)^±©Ýmë.­ëajÒ!j÷¢w­+"Ø^¥«-!©»õÇ«µ¨§¶­"¯y8ZK    Kú®¢×zYpzYpzYH²Ö§uÊ+­ç-yÒ!j÷°z{[iÉÛ^²×Ü"Y赧zZ~éܶ*'Â+a¥ªÚë^®Æ¬0|쵫^t(ºWaj÷­ Ø­².×!yÉ¢·^}«¥¶ö¥¹ë»-N¼®²)àjq/z{Gjwez·îËb¢qÞ­è¬$ÞZµã§÷§µ«·jëh×6;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Program Name:  Template - OnEventMode
;Description:   Template for OnEventMode GUI scripts
;Filename:      Template - OnEventMode.au3
;Used With:     
;Created by:    Jarvis J Stubblefield (support "at" vortexrevolutions "dot" com)
;Created on:    06/20/2006
;Modified on:   
;Modified by:   
;Version:       0.0.1
;Copyright:     Copyright (C) 2006 Vortex Revolutions. All Rights Reserved.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Declare Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Global $wHeight, $wWidth, $m_HWnd           ;Window variables
Global $wTitle                              ;Window variables II

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Preprocessor ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ;Set GUI to ONEvent Mode.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** File Installations ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Registry Information ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Command Line Options ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#cs UNCOMMENT FOR COMMANDLINE!
If $CmdLine[0] > 0 Then
    If StringRight($CmdLine[1], 4) = ".ext" Then
        _SomeFunc($CmdLine[1])
    Else
        _ErrorMsg("Incorret file extension. Please try again.")
        _TerminateApp()
    EndIf
EndIf
#ce

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$wHeight = 300
$wWidth  = 300
$wTitle  = "Template - OnEventMode"

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Creation ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;Main GUI Creation
$m_HWnd     = GUICreate($wTitle, $wWidth, $wHeight)
;Main Options
$m_Options  = GUICtrlCreateButton("Options", 5, ($wHeight - 25), 94, 20)
;Main Help
$m_Help     = GUICtrlCreateButton("Help", 103, ($wHeight - 25), 94, 20)
;Main Exit
$m_Exit     = GUICtrlCreateButton("Exit", 201, ($wHeight - 25), 94, 20)

;Disable Options and Help until added
GUICtrlSetState($m_Options, $GUI_DISABLE)
GUICtrlSetState($m_Help, $GUI_DISABLE)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Set Events ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;GUI Events Handled by _GUIEventHandler()
GUICtrlSetOnEvent($m_Options, "_GUIEventHandler")
GUICtrlSetOnEvent($m_Exit, "_GUIEventHandler")
GUICtrlSetOnEvent($m_Help, "_GUIEventHandler")

;System Events Handled by _SysEventHandler()
GUISetOnEvent($GUI_EVENT_CLOSE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_RESTORE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_RESIZED, "_SysEventHandler", $m_HWnd)
GUISetOnEvent($GUI_EVENT_DROPPED, "_SysEventHandler", $m_HWnd)

GUISetState(@SW_SHOW, $m_HWnd)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Main Program Loop ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1
    Sleep(100)
WEnd

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Event Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Func _GUIEventHandler()
    Switch @GUI_CtrlId
        Case $m_Exit
            _TerminateApp()
        Case $m_Options
        Case $m_Help
    EndSwitch
EndFunc

Func _SysEventHandler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            GUIDelete($m_HWnd)
            _TerminateApp()
        Case $GUI_EVENT_MINIMIZE
        Case $GUI_EVENT_RESTORE
        Case $GUI_EVENT_MAXIMIZE
        Case $GUI_EVENT_PRIMARYDOWN
        Case $GUI_EVENT_PRIMARYUP
        Case $GUI_EVENT_SECONDARYDOWN
        Case $GUI_EVENT_SECONDARYUP
        Case $GUI_EVENT_MOUSEMOVE
        Case $GUI_EVENT_RESIZED
        Case $GUI_EVENT_DROPPED
    EndSwitch
EndFunc

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Func _ErrorMsg($message)
    MsgBox(48 + 262144, "Error!", $message)
EndFunc

Func _TerminateApp()
    Exit
EndFunc

Using the above template and _GUIEventHandler() it should solve your issue. That is how I skirted around it, and for some reason I thought I didnt. :whistle:

Thanks,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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