Nicolas971 Posted July 28, 2010 Share Posted July 28, 2010 (edited) Hi people, I have a problem with my script. In fact, I have 2 functions and they work fine separately. But when I put them together, I have some problems. My problem : When I click OK button or when I try to close the window, by clicking on the X button, windows still running and it dosen't close. And it do it for the 2 functions. Furthermore, after the second GUI function, script stop and it dosen't continue. So, what I did wrong ? How can I validate (close) the windows by pressing OK button ? My code is the following : expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt('MustDeclareVars', 1) Opt("GuiOnEventMode", 1) ; --- Déclaration des variables globales --- ;Déclaration des variables pour la fonction "type_install" Dim $install_type, $val_endloop1, $radio1 ;Déclaration des variables pour la fonction "saisie_CBname" Dim $name, $id_tmp, $val_endloop2 ; --- Déclaration des fonctions --- ;Fcontion permettant d'indiquer si la CB dispose d'un acces Internet ou pas $val_endloop1 = 0 Func type_install() Local $msg1, $radio1, $radio2, $btn1 GUICreate("Prérequis d'installation", 400, 275) GUICtrlCreateLabel("Attention, Pour une installation totale, il est impératif de disposer d'une connexion au réseau Internet.", 50, 40, 300, 40, $SS_CENTER) GUICtrlCreateLabel("Veuillez indiquer ci-après, si la machine dispose d'un accès au réseau Internet ou non :", 50, 80, 300, 40, $SS_CENTER) $radio1 = GUICtrlCreateRadio("Oui, la Box dispose d'une connxion au réseau Internet.", 25, 140, 350, 20) $radio2 = GUICtrlCreateRadio("Non, la Box ne dispose pas de connxeion au réseau Internet.", 25, 180, 360, 20) GUICtrlSetState($radio2, $GUI_CHECKED) $btn1 = GUICtrlCreateButton("OK", 175, 230, 50, 20) GUICtrlSetOnEvent($btn1, "OkPressed1") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg1 = GUIGetMsg() If $val_endloop1 = 1 Then ExitLoop Select Case $msg1 = $GUI_EVENT_CLOSE Exit Case $msg1 = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED $install_type = 0 Case $msg1 = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED $install_type = 1 EndSelect WEnd EndFunc Func OkPressed1() $val_endloop1 = 1 EndFunc ;Fonction permettant de saisir le nom de la CB $val_endloop2 = 0 Func saisie_CBname() Local $btn, $msg2 GUICreate(" Nom de la Box", 300, 175) GUICtrlCreateLabel("Veuillez saisir le nom de la Box.", 20, 20, 250, 30, $SS_CENTER) $id_tmp = GUICtrlCreateInput("", 100, 60, 100, 20) $btn = GUICtrlCreateButton("Valider", 112, 120, 75, 20) GUICtrlSetOnEvent($btn, "OkPressed2") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg2 = GUIGetMsg() If $msg2 = $GUI_EVENT_CLOSE Then Exit If $val_endloop2 = 1 Then ExitLoop WEnd EndFunc Func OkPressed2() $name = GUICtrlRead($id_tmp) If $name = "" Then MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.") ElseIf StringIsSpace($name) Then MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.") Else $val_endloop2 = 1 EndIf EndFunc ; --- Appel des fonctions --- ;Choix du type d'installation type_install() ;Saisie du nom de la Box saisie_CBname() PS : Sorry for my english. Edited July 28, 2010 by Nicolas971 Link to comment Share on other sites More sharing options...
water Posted July 28, 2010 Share Posted July 28, 2010 You mix the two GUI concepts: MessageLoop Mode and OnEvent Mode. Please see the help file: GUI Reference -> GUI Concepts My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 28, 2010 Moderators Share Posted July 28, 2010 Nicolas971,You were using both OnEvent and GetMessage modes - you shoudl only use one or the other in your script. Here is the script rewritten in GetMessage mode - with a few other changes for you to spot: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt('MustDeclareVars', 1) ; --- Déclaration des variables globales --- ;Déclaration des variables Global Global $install_type, $name ; --- Déclaration des fonctions --- ;Fcontion permettant d'indiquer si la CB dispose d'un acces Internet ou pas Func type_install() Local $hGUI1 = GUICreate("Prérequis d'installation", 400, 275) GUICtrlCreateLabel("Attention, Pour une installation totale, il est impératif de disposer d'une connexion au réseau Internet.", 50, 40, 300, 40, $SS_CENTER) GUICtrlCreateLabel("Veuillez indiquer ci-après, si la machine dispose d'un accès au réseau Internet ou non :", 50, 80, 300, 40, $SS_CENTER) GUIStartgroup() Local $radio1 = GUICtrlCreateRadio("Oui, la Box dispose d'une connxion au réseau Internet.", 25, 140, 350, 20) Local $radio2 = GUICtrlCreateRadio("Non, la Box ne dispose pas de connxeion au réseau Internet.", 25, 180, 360, 20) GUICtrlSetState($radio2, $GUI_CHECKED) Local $btn1 = GUICtrlCreateButton("OK", 175, 230, 50, 20) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btn1 If GUICtrlRead($radio1) = 1 Then $install_type = 0 Else $install_type = 1 EndIf GUIDelete($hGUI1) ExitLoop EndSwitch WEnd EndFunc ;Fonction permettant de saisir le nom de la CB Func saisie_CBname() Local $hGUI2 = GUICreate(" Nom de la Box", 300, 175) GUICtrlCreateLabel("Veuillez saisir le nom de la Box.", 20, 20, 250, 30, $SS_CENTER) Local $id_tmp = GUICtrlCreateInput("", 100, 60, 100, 20) Local $btn = GUICtrlCreateButton("Valider", 112, 120, 75, 20) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btn $name = GUICtrlRead($id_tmp) If $name = "" Then MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.") ElseIf StringIsSpace($name) Then MsgBox(0,"Erreur","Aucune saisie détectée. Veuillez cliquer sur ""OK"" et saisir un nom pour la machine.") GUICtrlSetData($id_tmp, "") Else ExitLoop EndIf EndSwitch WEnd EndFunc ; --- Appel des fonctions --- ;Choix du type d'installation type_install() ;Saisie du nom de la Box saisie_CBname() MsgBox(0, "Resultat", "Type Install = " & $install_type & @CRLF & "CBname = " & $name)Could I suggest you go and read the first part of the Wiki tutorial "Variables - using Global, Local and ByRef" - you seem a little confused over whether to use Global or Local scope for your variables. As you can see I have only declared 2 variables as Global.Please ask if you have any questions. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Nicolas971 Posted July 28, 2010 Author Share Posted July 28, 2010 You mix the two GUI concepts: MessageLoop Mode and OnEvent Mode.Please see the help file: GUI Reference -> GUI ConceptsOk, thx.I read it and to test, I just comment the line "Opt("GuiOnEventMode", 1)". Now, I can close my window and exit script correctly. But of course, the OK button doesn't work. So how can I replace the "GUICtrlSetOnEvent($btn1, "OkPressed1"" ? Because I need an OK button to validate choices/selections.PS : Sorry I'm new (less 2 weeks experiences with AutoIT), I'm not a dev (just have some base in prog), so it's a little difficult for me Link to comment Share on other sites More sharing options...
Nicolas971 Posted July 28, 2010 Author Share Posted July 28, 2010 (edited) Hi Melba23, And a big thx It works fine. I'm going to read and learn how you did that ! Thx both of you for your contribution. Edited July 28, 2010 by Nicolas971 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now