Jump to content
Sign in to follow this  
PcExpert

GUICtrlSetOnEvent() executes before doing anything

Recommended Posts

PcExpert

Hi all,

I have a script which uses the OnEventMode. In this script I have the following line:

GUICtrlSetOnEvent(-1, ChangePage("Do this"))

Directly above that line, I have a button, which should execute the function when I click on it.

I don't know why, but this line executes before I'm doing anything, when I comment the line the problem is gone. The function that is called handles the ' Do this' part.

Does anyone know why this happens?

Edited by PcExpert

Share this post


Link to post
Share on other sites
somdcomputerguy

The -1 assigns it to whatever control is created right before it, be it a button, checkbox, radio, probably even the whole GUI.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
PcExpert

This is what I have so far:

#include<string.au3>
#include <GUIConstantsEx.au3>
Global $INI_General = "Database\settings.ini"
Global $TITLE = "Servicedesk"
Global $CurrentPage = "Incident_overview"
Opt("GUIOnEventMode", 1)
$gui_main = GUICreate($TITLE, 680, 395)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIExit")
GUICtrlCreateMenu("&Bestand")
$incident_listview = GUICtrlCreateListView("Incident nr.|Aanmelder|Datum|Probleem Omschrijving ", 90, 35, 580, 330)
$incident_view_type_label = GUICtrlCreateLabel("Incident status:" , 400, 10)
$incident_view_type = GUICtrlCreateCombo("Afgemeld" , 490, 8, 100)
GUICtrlSetData(-1, "Niet afgemeld", "Niet afgemeld")
GUICtrlCreateButton("Incidenten", 5, 25, 80, 25)
GUICtrlCreateGroup("Klanten",2, 60, 86, 102)
GUICtrlCreateButton("Toevoegen", 5, 80, 80, 25)
GUICtrlSetOnEvent(-1, ChangePage("Klant toevoegen"))
GUICtrlCreateButton("Wijzigen", 5, 105, 80, 25)
GUICtrlCreateButton("Verwijderen", 5, 130, 80, 25)
GUISetState(@SW_HIDE, $gui_main)


StartUp()


while 1
Sleep(10)
WEnd




















Func startup()
if FileExists("Database\settings.ini") Then
    ShowGUI()
Else
DirCreate("Database")
$NewPass = InputBox("Wachtwoord", "Voer a.u.b een nieuw wachtwoord in voor de admin gebruiker", "", "*", 250, 140)
If $NewPass = Not "" Then
    IniWrite($INI_General, "General", "Password", _StringEncrypt(1, $NewPass, "ndgJet591Xvk0lPq2&#21nStndP83ld", 6))
Else
    startup()
EndIf
EndIf
EndFunc

Func ShowGUI()
GUISetState(@SW_SHOW, $gui_main)
EndFunc

Func GUIExit()
Exit
EndFunc

Func ChangePage($Pagename)
If $CurrentPage = "Incident_overview"   Then
GUICtrlSetState($incident_listview, $GUI_HIDE)
GUICtrlSetState($incident_view_type, $GUI_HIDE)
GUICtrlSetState($incident_view_type_label, $GUI_HIDE)
EndIf
If $Pagename = "Incident_overview" Then
GUICtrlSetState($incident_listview, $GUI_SHOW)
GUICtrlSetState($incident_view_type, $GUI_SHOW)
GUICtrlSetState($incident_view_type_label, $GUI_SHOW)
ElseIf $Pagename = "Klant toevoegen" Then
MsgBox(0, "", "This is a test")
EndIf
EndFunc

@SnowMaker

Even when I assign a variable to the control, it still does the same :mellow:

Edited by PcExpert

Share this post


Link to post
Share on other sites
Jos

It doesn't work like that.

The second parameter in GUICtrlSetOnEvent() needs to be a string containing the Func to be called without any parameter.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
PcExpert

Hmm, okay.. I think I can live with that :mellow: ... thanks for the quick help :( Why is it not possible actually?

Edited by PcExpert

Share this post


Link to post
Share on other sites
martin

Hmm, okay.. I think I can live with that :mellow: ... thanks for the quick help :( Why is it not possible actually?

Why is what not possible? If you mean why can' t you have a function with parameters for an event then there are ways round it.

Easiest way and probably best for most situations is to use the @GUI_CTRLID macro. Eg

$Button = GuiCtrlCreateButton(.......
GuiCtrlSetOnEvent(-1,"abcde")
.
.
Func abcde()
 Switch @GUI_CTRLID
 Case Button
    fghij("something",$orother)
.
.
..


endfunc

Sometimes even this is a little cumbersome, especially when creating controls dynamically, and then the udf in my signature allows you to use parameters when you set the event function.

Edited by martin

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
somdcomputerguy

@SnowMaker

Even when I assign a variable to the control, it still does the same :(

:mellow:

I think you misunderstood what I was getting at, but it seems I wasn't going in right direction anyway. Good luck in overcoming this obstacle.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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  

×