amosrinat Posted April 21, 2019 Share Posted April 21, 2019 (edited) I have created a script at which there are three combo boxes in separate functions and a Button configured to open a FileOpenDialog. This dialog doesn't work unless I disable the line AutoItSetOption('GUIOnEventMode', 1). Please help. expandcollapse popup#include <GUIConstants.au3> #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> AutoItSetOption('GUIOnEventMode', 1) $_1 = GUICreate("LanSweeper Update tool", 537, 356, 248, 137) $Button2 = GUICtrlCreateButton("Exit", 390, 236, 75, 25, 0) $CsvInput1 = GUICtrlCreateInput("", 145, 19, 225, 21) $Button1 = GUICtrlCreateButton("Browse...", 390, 16, 75, 25, 0) GUISetOnEvent($GUI_EVENT_CLOSE, 'quit') $combo1 = GUICtrlCreateCombo("", 42, 146, 120, 25) GUICtrlSetData(-1, 'Computer_Name|Business_Owner|Group') GUICtrlSetOnEvent($combo1, 'setgrp') $combo2 = GUICtrlCreateCombo('', 42, 186, 120, 25) GUICtrlSetOnEvent($combo2, 'fSetgrp2') $combo3 = GUICtrlCreateCombo('', 42, 226, 120, 25) $Checkbox1 = GUICtrlCreateCheckbox("Check to enable specific selection in LanSweeper", 40, 72, 273, 17) $Label1 = GUICtrlCreateLabel("Select to match SQL (combo) with input csv", 40, 118, 211, 17) $Input1 = GUICtrlCreateInput("", 145, 19, 225, 21) $Label2 = GUICtrlCreateLabel("sdf", 180, 150, 108, 25) $Label3 = GUICtrlCreateLabel("sdfg", 180, 190, 108, 25) $Label4 = GUICtrlCreateLabel("sdf", 180, 230, 108, 25) GUISetState() ;~ While 1 ;~ Sleep(50) ;~ WEnd while 1 $nMsg = GUIGetMsg() Local $line,$List,$col,$arrCsv,$sHdr1 Select Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg = $Button2 Exit Case $nMsg = $Button1 $csv=FileOpenDialog("Open", "C:\" ,"csv files (*.csv)") GUICtrlSetData($Input1,$csv) ;~ _FileReadToArray($csv,$arrCsv,Default,",");[R][C] ;~ _ArrayDisplay($arrCsv) ;~ $sHdr1 = $arrCsv[1][0] ;~ $sHdr2 = $arrCsv[1][1] ;~ $sHdr3 = $arrCsv[1][2] ;~ GUICtrlSetData($Label2,$sHdr1) ;~ GUICtrlSetData($Label3,$sHdr2) ;~ GUICtrlSetData($Label4,$sHdr3) ;;; Computer, B.Owner, Group ;~ MsgBox(0,"",$sHdr1 & " " & $sHdr2 &" " & $sHdr3) EndSelect WEnd Func setgrp() Global $c_msg = GUICtrlRead($combo1) Switch $c_msg Case 'Computer_Name' GUICtrlSetData($combo2, '') GUICtrlSetData($combo2, 'Business_Owner|Group') Case 'Business_Owner' GUICtrlSetData($combo2, '') GUICtrlSetData($combo2, 'Computer_Name|Group') Case 'Group' GUICtrlSetData($combo2, '') GUICtrlSetData($combo2, 'Computer_Name|Business_Owner') EndSwitch EndFunc Func fSetgrp2() $c_msg2 = GuictrlRead($combo2) Switch $c_msg2 Case 'Computer_Name' GUICtrlSetData($combo3, '') $sMsg = StringReplace('Business_Owner|Group',$c_msg,"") GUICtrlSetData($combo3,$sMsg) Case 'Business_Owner' GUICtrlSetData($combo3, '') $sMsg = StringReplace('Computer_Name|Group',$c_msg,"") GUICtrlSetData($combo3,$sMsg) Case 'Group' GUICtrlSetData($combo3, '') $sMsg = StringReplace('Computer_Name|Business_Owner',$c_msg,"") GUICtrlSetData($combo3,$sMsg) EndSwitch EndFunc Func quit() Exit EndFunc Edited April 21, 2019 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 21, 2019 Moderators Share Posted April 21, 2019 amosrinat, Welcome to the AutoIt forums. You cannot mix OnEvent and MessageLoop in the same script. So you need to decide which you want to use as if you use OnEvent mode, GUIGetMsg will never return any events - once you disable OnEvent mode it starts working correctly, as you have discovered. 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...
KickStarter15 Posted April 22, 2019 Share Posted April 22, 2019 @amosrinat, as what Melba said, you can decide which is which. You can disable the OnEvent mode on [param] 0 "AutoItSetOption('GUIOnEventMode', 0)" or you may do a Func () code same as below to make you script working. Func Button1() $csv=FileOpenDialog("Open", "C:\" ,"csv files (*.csv)") GUICtrlSetData($Input1,$csv) EndFunc KS15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
amosrinat Posted April 23, 2019 Author Share Posted April 23, 2019 Thank you for your adivce, I have changed the code (below) to include a fButton1 function and now nothing happens. the GUI shows for a second and disappears. please advice. Thanks, Amos ------------------------ Code #include <GUIConstants.au3> #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> AutoItSetOption('GUIOnEventMode', 1) $_1 = GUICreate("LanSweeper Update tool", 537, 356, 248, 137) $Button2 = GUICtrlCreateButton("Exit", 390, 236, 75, 25, 0) $CsvInput1 = GUICtrlCreateInput("", 145, 19, 225, 21) $Button1 = GUICtrlCreateButton("Browse...", 390, 16, 75, 25, 0) GUICtrlSetOnEvent($Button1,'fButton1') ; *********** new line ************ GUISetOnEvent($GUI_EVENT_CLOSE, 'quit') $combo1 = GUICtrlCreateCombo("", 42, 146, 120, 25) GUICtrlSetData(-1, 'Computer_Name|Business_Owner|Group') GUICtrlSetOnEvent($combo1, 'fsetgrp') $combo2 = GUICtrlCreateCombo('', 42, 186, 120, 25) GUICtrlSetOnEvent($combo2, 'fSetgrp2') $combo3 = GUICtrlCreateCombo('', 42, 226, 120, 25) $Checkbox1 = GUICtrlCreateCheckbox("Check to enable specific selection in LanSweeper", 40, 72, 273, 17) $Label1 = GUICtrlCreateLabel("Select to match SQL (combo) with input csv", 40, 118, 211, 17) $Input1 = GUICtrlCreateInput("", 145, 19, 225, 21) $Label2 = GUICtrlCreateLabel("sdf", 180, 150, 108, 25) $Label3 = GUICtrlCreateLabel("sdfg", 180, 190, 108, 25) $Label4 = GUICtrlCreateLabel("sdf", 180, 230, 108, 25) GUISetState() Local $line,$List,$col,$arrCsv,$sHdr1 $nMsg = GUIGetMsg() Func fButton1() ; ************ new function ********* $csv=FileOpenDialog("Open", "C:\" ,"csv files (*.csv)") GUICtrlSetData($Input1,$csv) EndFunc Func fsetgrp() Global $c_msg = GUICtrlRead($combo1) Switch $c_msg Case 'Computer_Name' GUICtrlSetData($combo2, '') GUICtrlSetData($combo2, 'Business_Owner|Group') Case 'Business_Owner' GUICtrlSetData($combo2, '') GUICtrlSetData($combo2, 'Computer_Name|Group') Case 'Group' GUICtrlSetData($combo2, '') GUICtrlSetData($combo2, 'Computer_Name|Business_Owner') EndSwitch EndFunc Func fSetgrp2() $c_msg2 = GuictrlRead($combo2) Switch $c_msg2 Case 'Computer_Name' GUICtrlSetData($combo3, '') $sMsg = StringReplace('Business_Owner|Group',$c_Msg,"") GUICtrlSetData($combo3,$sMsg) Case 'Business_Owner' MsgBox(0,"",$c_msg2) GUICtrlSetData($combo3, '') $sMsg = StringReplace('Computer_Name|Group',$c_Msg,"") MsgBox(0,"",$sMsg) GUICtrlSetData($combo3,$sMsg) Case 'Group' GUICtrlSetData($combo3, '') $sMsg = StringReplace('Computer_Name|Business_Owner',$c_msg,"") GUICtrlSetData($combo3,$sMsg) EndSwitch EndFunc Func quit() Exit EndFunc ----------------------------- End of code Link to comment Share on other sites More sharing options...
Nine Posted April 23, 2019 Share Posted April 23, 2019 You still need a loop otherwise the program will just exit. This line is useless : $nMsg = GUIGetMsg(). So replace it with: While True Sleep (100) Wend And, if you post code please use <> just before emoticon. It will help us to help you... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
amosrinat Posted April 24, 2019 Author Share Posted April 24, 2019 I'm on track again, thank you all. Amos 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