vishu Posted July 22, 2010 Share Posted July 22, 2010 (edited) Hi, I have a problem with my script when I run the below code I have a button defined as below: $Startappbuttn = GUICtrlCreateButton("Start",120,450,70 On clicking this button the function Batch should be called through the Case statement as below: Case $msg = $Startappbuttn Batch() If I comment Batch() function in the case statemtn the script does not exit if not it is exiting rapidly after launching. Pl suggest. Since I could not upload the script i am appending it with this text.Sorry for the inconvinence. Usge of the script: Run the script and click on Automate button a GUI popsup in which we have to click on the start button, but as tole it only happens if I comment teh Batch function in the case statement. Thanks, Vishwas expandcollapse popup#include <Excel.au3> ;library for doing excel operations #include <GUIConstantsEx.au3> #include <Misc.au3> #include <Array.au3> #include <file.au3> Opt("GUICoordMode", 1) local $readedit,$mylist Global $currentlistselection,$hCombo ;$redvalue is the variable which accepts the 3 digit numerals for reading the row numbers from excel file Global $redvalue = String(3),$oExcelclose,$sCellValue,$oExcel ;Checking to see if the AllStreamDetails.xls is already opened If WinExists("Microsoft Excel - AllStreamDetails.xls") Then MsgBox(0, "", "The Excel file is already open") Else ;Reading the files from Desktop ;This file should already exist on the desktop $sFilePath1 = @DesktopDir & "\AllStreamDetails.xls" ;Opening the Excel file $oExcel = _ExcelBookOpen($sFilePath1) EndIf ;Error handling in case the excel file is not existing If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist - Please copy the AllStreamDetails.xls onto your desktop and try") Exit EndIf ;Calling the GUI create function createGUI() Func createGUI() $hGUI = GUICreate("TS-Automator",350,200) GUICtrlCreateLabel("Enter the Row Number of the stream to be loaded :",10,20,250,75) Global $readedit = GUICtrlCreateInput(" ",270,15,75,20) GUICtrlCreateLabel("Select the Frequency to be set from the list:",10,50,250,75) ;Combo box with default value as 473.000 Global $hCombo = GUICtrlCreateCombo("473.000", 270, 50, 75, 20) ;Combo box with range of frequencies GUICtrlSetData(-1, "479.000|485.000|491.000|497.000|503.000|509.000|515.000|521.000|527.000|533.000|539.000|545.000|551.000|557.000|563.000|569.000|575.000|581.000|587.000|593.000|599.000|605.000|611.000|617.000|623.000|629.000|635.000|641.000|647.000|653.000|659.000|665.000|671.000|677.000|683.000|689.000|695.000|701.000|707.000|713.000|719.000|725.000|731.000|743.000|749.000|755.000|761.000|767.000", "") ; add other item snd set a new default Global $Automateappbuttn = GUICtrlCreateButton("Automate",220,120,70) GUISetOnEvent(-1,'Automate') Global $setvaluebuttn = GUICtrlCreateButton("Set Value",30,120,70,25) GUISetOnEvent(-1,"validate") Global $exitappbuttn = GUICtrlCreateButton("Exit",120,120,70) ;Making the GUI visible to the end user GUISetState() EndFunc ;This function validates the user entry of the Excel row number based on positive value calls the setvalue function Func validate() $redvalue = GUICtrlRead($readedit) If(Int($redvalue)) Then setvalue() Else MsgBox(16, "Error", "Please enter numeric values only") GUICtrlSetData($readedit,"") EndIf EndFunc Func Automate() $hGUI = GUICreate("Automate",300,150) GUICtrlCreateLabel("Enter the First Stream Path :",10,20,250,75) GUICtrlCreateLabel("Enter the Second Stream Path :",10,60,250,75) Global $readfirstautoedit = GUICtrlCreateInput(" ",170,20,100,20) Global $readsecondautoedit = GUICtrlCreateInput(" ",170,60,100,20) ;Pointing to the already defined exit function in switch case Global $exitappbuttn = GUICtrlCreateButton("Exit",120,120,70) ;~ Global $getfirstpath, $getsecondpath ;~ $getfirstpath = $readfirstautoedit ;MsgBox(0, "", "I have been called: ",$readfirstautoedit , 20000) GUISetState() sleep(2000) MsgBox(16, "Error", $readfirstautoedit) ;~ sleep(1000) EndFunc Func setvalue() ;If condition which reads the combobox to find the current selection If GUICtrlRead($hCombo) <> $currentlistselection Then ;Reads the new selection value to $hCombo variable $currentlistselection = GUICtrlRead($hCombo) ;MsgBox(0, "", "The Cell Value is: " & @CRLF & $currentlistselection, 2) EndIf ;Activates the already opened Dektec application WinActivate("DekTec StreamXpress - Transport-Stream Player") ;Moves the application to screen co-ordinates to 0,0 WinMove("DekTec StreamXpress - Transport-Stream Player", "", 0, 0) ;Delay needed to ensure the dektec in moved to the left top corner Sleep(500) ;Reading the file -> $oExcel, Reading the row number -> $redvalue,Reading the column -> 2 If IsString($sCellValue)Then $sCellValue = _ExcelReadCell($oExcel, $redvalue, 2) MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue, 2) ElseIf $sCellValue = "" Then MsgBox(0, "", "The Cell number selected is invalid: ") EndIf ;This commented lines reads the current stream being played by the streamer xpress app ;local $getstreamervalue ;$getstreamervalue = ControlGetText("DekTec StreamXpress - Transport-Stream Player", "", "Edit1") ;MsgBox(0, "", "The stream being played is: " & @CRLF & $getstreamervalue, 2) ;This commented lines reads the current frequency selected in the streamer xpress app ;local $getstreamerfreq ;$getstreamerfreq = ControlGetText("Streamer set Frequency is:", "", "Edit2") ;MsgBox(0, "", "The streamer frequency Value is: " & @CRLF & $getstreamerfreq, 2) local $setstream ;Button1 clicks the "open" button in Dektec app ControlClick("DekTec StreamXpress - Transport-Stream Player", "", "Button1") ;Activating the UI which appears after clicking the "open" button WinActivate("Open MPEG-2 Transport Stream") ;Delay provided to ensure the above window is launched sleep(2000) ;Setting the stream path read from "$sCellValue"(Excel file) onto the Text box(Edit1) before the Open button $setstream = ControlSetText ("Open MPEG-2 Transport Stream", " ", "Edit1", $sCellValue) ;MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue, 2) ;Delay provided to esnure the read stream path is copied onto the textbox(Edit1) sleep(1000) ;Pressing the Open button(Button2) to ensure the selected stream is opened in streamer application ControlClick("Open MPEG-2 Transport Stream", "", "Button2") ;MsgBox(0, "", "The stream being played is: " & @CRLF & $setstream, 2) ;WinActivate("DekTec StreamXpress - Transport-Stream Player") WinActivate("TS-Automator") local $getappfreq ;Reading the frequency from our application and storing in $getappfreq $getappfreq = ControlGetText("TS-Automator", "", "Edit2") ;~ MsgBox(0, "", "The application frequency Value is: " & @CRLF & $getappfreq, 2) local $setappfreq ;Copying the read frequency value to the streamer application(Edit6) text box $setappfreq = ControlSetText ( "DekTec StreamXpress - Transport-Stream Player", " ", "Edit6", $getappfreq) ;Ensuring the playback is stopped in streamer application ControlClick("DekTec StreamXpress - Transport-Stream Player", "", "Button21","left",2) sleep(1000) ;Ensuring the play button is pressed to start the current selected stream playback ControlClick("DekTec StreamXpress - Transport-Stream Player", "", "Button19","left",2) EndFunc While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE WinActivate("Microsoft Excel - AllStreamDetails.xls") _ExcelBookClose($oExcel,0) Exit Case $msg = $setvaluebuttn validate() Case $msg = $Automateappbuttn Automate() Case $msg = $exitappbuttn _ExcelBookClose($oExcel,0) Exit EndSelect WEnd Edited July 23, 2010 by SmOke_N added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 22, 2010 Moderators Share Posted July 22, 2010 vishu,Firstly, could you please edit your post to add code tags - put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). It makes the thread much easier to read! Now, you say you have problems with $Startappbuttn and Batch(). Neither of these terms appear in the script you posted. You also say that function Automate() brings up a a GUI with a "start" button - can you see such a button here: Func Automate() $hGUI = GUICreate("Automate", 300, 150) GUICtrlCreateLabel("Enter the First Stream Path :", 10, 20, 250, 75) GUICtrlCreateLabel("Enter the Second Stream Path :", 10, 60, 250, 75) Global $readfirstautoedit = GUICtrlCreateInput(" ", 170, 20, 100, 20) Global $readsecondautoedit = GUICtrlCreateInput(" ", 170, 60, 100, 20) ;Pointing to the already defined exit function in switch case Global $exitappbuttn = GUICtrlCreateButton("Exit", 120, 120, 70) ;~ Global $getfirstpath, $getsecondpath ;~ $getfirstpath = $readfirstautoedit ;MsgBox(0, "", "I have been called: ",$readfirstautoedit , 20000) GUISetState() Sleep(2000) MsgBox(16, "Error", $readfirstautoedit) ;~ sleep(1000) EndFunc ;==>AutomateIf you want help, you need to give us some code that actually reflects the problem you are having. 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...
vishu Posted July 23, 2010 Author Share Posted July 23, 2010 (edited) Dear MVP, Am so sorry I missed it during copy paste I have taken the old script. Sorry for the inconvinence. Pl find the lates one as below. expandcollapse popup#include <Excel.au3> ;library for doing excel operations #include <GUIConstantsEx.au3> #include <Misc.au3> #include <Array.au3> #include <file.au3> Opt("GUICoordMode", 1) local $readedit,$mylist Global $currentlistselection,$hCombo ;$redvalue is the variable which accepts the 3 digit numerals for reading the row numbers from excel file Global $redvalue = String(3),$oExcelclose,$sCellValue,$oExcel,$Startappbuttn ;Checking to see if the AllStreamDetails.xls is already opened If WinExists("Microsoft Excel - AllStreamDetails.xls") Then MsgBox(0, "", "The Excel file is already open") Else ;Reading the files from Desktop ;This file should already exist on the desktop $sFilePath1 = @DesktopDir & "\AllStreamDetails.xls" ;Opening the Excel file $oExcel = _ExcelBookOpen($sFilePath1) EndIf ;Error handling in case the excel file is not existing If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist - Please copy the AllStreamDetails.xls onto your desktop and try") Exit EndIf ;Calling the GUI create function createGUI() Func createGUI() $hGUI = GUICreate("TS-Automator",350,200) GUICtrlCreateLabel("Enter the Row Number of the stream to be loaded :",10,20,250,75) Global $readedit = GUICtrlCreateInput(" ",270,15,75,20) GUICtrlCreateLabel("Select the Frequency to be set from the list:",10,50,250,75) ;Combo box with default value as 473.000 Global $hCombo = GUICtrlCreateCombo("473.000", 270, 50, 75, 20) ;Combo box with range of frequencies GUICtrlSetData(-1, "479.000|485.000|491.000|497.000|503.000|509.000|515.000|521.000|527.000|533.000|539.000|545.000|551.000|557.000|563.000|569.000|575.000|581.000|587.000|593.000|599.000|605.000|611.000|617.000|623.000|629.000|635.000|641.000|647.000|653.000|659.000|665.000|671.000|677.000|683.000|689.000|695.000|701.000|707.000|713.000|719.000|725.000|731.000|743.000|749.000|755.000|761.000|767.000", "") ; add other item snd set a new default Global $Automateappbuttn = GUICtrlCreateButton("Automate",220,120,70) GUISetOnEvent(-1,'Automate') Global $setvaluebuttn = GUICtrlCreateButton("Set Value",30,120,70,25) GUISetOnEvent(-1,"validate") Global $exitappbuttn = GUICtrlCreateButton("Exit",120,120,70) ;Making the GUI visible to the end user GUISetState() EndFunc ;This function validates the user entry of the Excel row number based on positive value calls the setvalue function Func validate() $redvalue = GUICtrlRead($readedit) If(Int($redvalue)) Then setvalue() Else MsgBox(16, "Error", "Please enter numeric values only") GUICtrlSetData($readedit,"") EndIf EndFunc Func Automate() $hGUI = GUICreate("Automate",400,500) GUICtrlCreateLabel("Enter the First Stream Path :",10,20,250,75) GUICtrlCreateLabel("Enter the Second Stream Path :",10,60,250,75) GUICtrlCreateLabel("Enter the Third Stream Path :",10,100,250,75) GUICtrlCreateLabel("Enter the Fourth Stream Path :",10,140,250,75) GUICtrlCreateLabel("Enter the Fifth Stream Path :",10,180,250,75) GUICtrlCreateLabel("Enter the Sixth Stream Path :",10,220,250,75) GUICtrlCreateLabel("Enter the Seventh Stream Path :",10,260,250,75) GUICtrlCreateLabel("Enter the Eighth Stream Path :",10,300,250,75) GUICtrlCreateLabel("Enter the Nineth Stream Path :",10,340,250,75) GUICtrlCreateLabel("Enter the Tenth Stream Path :",10,380,250,75) Global $readfirstautoedit = GUICtrlCreateInput("a ",170,20,200,20) Global $readsecondautoedit = GUICtrlCreateInput("b ",170,60,200,20) Global $readthirdautoedit = GUICtrlCreateInput("c ",170,100,200,20) Global $readfourthautoedit = GUICtrlCreateInput("d ",170,140,200,20) Global $readfifthautoedit = GUICtrlCreateInput("e ",170,180,200,20) Global $readsixthautoedit = GUICtrlCreateInput("f ",170,220,200,20) Global $readseventhautoedit = GUICtrlCreateInput("g ",170,260,200,20) Global $readeighthautoedit = GUICtrlCreateInput("h ",170,300,200,20) Global $readninethautoedit = GUICtrlCreateInput("i ",170,340,200,20) Global $readTenthautoedit = GUICtrlCreateInput("j ",170,380,200,20) ;Loop button checkbox Global $chkbox = GUICtrlCreateCheckbox("Loop", 50, 420, 120, 20) ;Creating the Start button $Startappbuttn = GUICtrlCreateButton("Start",120,450,70) ;GUISetOnEvent(-1,'Batch') ;The object refers to the already defined Exit button Global $exitappbuttn = GUICtrlCreateButton("Exit",220,450,70) GUISetState() EndFunc Func Batch() MsgBox(0, "", "The stream being played is: " & @CRLF & $readfirstautoedit, 2) EndFunc Func setvalue() ;If condition which reads the combobox to find the current selection If GUICtrlRead($hCombo) <> $currentlistselection Then ;Reads the new selection value to $hCombo variable $currentlistselection = GUICtrlRead($hCombo) ;MsgBox(0, "", "The Cell Value is: " & @CRLF & $currentlistselection, 2) EndIf ;Activates the already opened Dektec application WinActivate("DekTec StreamXpress - Transport-Stream Player") ;Moves the application to screen co-ordinates to 0,0 WinMove("DekTec StreamXpress - Transport-Stream Player", "", 0, 0) ;Delay needed to ensure the dektec in moved to the left top corner Sleep(500) ;Reading the file -> $oExcel, Reading the row number -> $redvalue,Reading the column -> 2 If IsString($sCellValue)Then $sCellValue = _ExcelReadCell($oExcel, $redvalue, 2) MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue, 2) ElseIf $sCellValue = "" Then MsgBox(0, "", "The Cell number selected is invalid: ") EndIf ;This commented lines reads the current stream being played by the streamer xpress app ;local $getstreamervalue ;$getstreamervalue = ControlGetText("DekTec StreamXpress - Transport-Stream Player", "", "Edit1") ;MsgBox(0, "", "The stream being played is: " & @CRLF & $getstreamervalue, 2) ;This commented lines reads the current frequency selected in the streamer xpress app ;local $getstreamerfreq ;$getstreamerfreq = ControlGetText("Streamer set Frequency is:", "", "Edit2") ;MsgBox(0, "", "The streamer frequency Value is: " & @CRLF & $getstreamerfreq, 2) local $setstream ;Button1 clicks the "open" button in Dektec app ControlClick("DekTec StreamXpress - Transport-Stream Player", "", "Button1") ;Activating the UI which appears after clicking the "open" button WinActivate("Open MPEG-2 Transport Stream") ;Delay provided to ensure the above window is launched sleep(2000) ;Setting the stream path read from "$sCellValue"(Excel file) onto the Text box(Edit1) before the Open button $setstream = ControlSetText ("Open MPEG-2 Transport Stream", " ", "Edit1", $sCellValue) ;MsgBox(0, "", "The Cell Value is: " & @CRLF & $sCellValue, 2) ;Delay provided to esnure the read stream path is copied onto the textbox(Edit1) sleep(1000) ;Pressing the Open button(Button2) to ensure the selected stream is opened in streamer application ControlClick("Open MPEG-2 Transport Stream", "", "Button2") ;MsgBox(0, "", "The stream being played is: " & @CRLF & $setstream, 2) ;WinActivate("DekTec StreamXpress - Transport-Stream Player") WinActivate("TS-Automator") local $getappfreq ;Reading the frequency from our application and storing in $getappfreq $getappfreq = ControlGetText("TS-Automator", "", "Edit2") ;~ MsgBox(0, "", "The application frequency Value is: " & @CRLF & $getappfreq, 2) local $setappfreq ;Copying the read frequency value to the streamer application(Edit6) text box $setappfreq = ControlSetText ( "DekTec StreamXpress - Transport-Stream Player", " ", "Edit6", $getappfreq) ;Ensuring the playback is stopped in streamer application ControlClick("DekTec StreamXpress - Transport-Stream Player", "", "Button21","left",2) sleep(1000) ;Ensuring the play button is pressed to start the current selected stream playback ControlClick("DekTec StreamXpress - Transport-Stream Player", "", "Button19","left",2) EndFunc While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE WinActivate("Microsoft Excel - AllStreamDetails.xls") _ExcelBookClose($oExcel,0) Exit Case $msg = $setvaluebuttn validate() Case $msg = $Automateappbuttn Automate() Case $msg = $Startappbuttn Batch() Case $msg = $exitappbuttn _ExcelBookClose($oExcel,0) Exit EndSelect WEnd Edited July 23, 2010 by Jos added correct Autoit tags Link to comment Share on other sites More sharing options...
GeekOrGuru Posted July 23, 2010 Share Posted July 23, 2010 I'm a total Noob, but aren't all If statements to be followed by Then, ElseIf...Then, Else...Then, EndIf? ;Checking to see if the AllStreamDetails.xls is already opened If WinExists("Microsoft Excel - AllStreamDetails.xls") Then MsgBox(0, "", "The Excel file is already open") Else ;Reading the files from Desktop ;This file should already exist on the desktop $sFilePath1 = @DesktopDir & "\AllStreamDetails.xls" ;Opening the Excel file $oExcel = _ExcelBookOpen($sFilePath1) EndIf;This function validates the user entry of the Excel row number based on positive value calls the setvalue functionFunc validate() $redvalue = GUICtrlRead($readedit) If(Int($redvalue)) Then setvalue() Else MsgBox(16, "Error", "Please enter numeric values only") GUICtrlSetData($readedit,"") EndIfEndFunc ;If condition which reads the combobox to find the current selection If GUICtrlRead($hCombo) <> $currentlistselection Then ;Reads the new selection value to $hCombo variable $currentlistselection = GUICtrlRead($hCombo) ;MsgBox(0, "", "The Cell Value is: " & @CRLF & $currentlistselection, 2) EndIf ;Activates the already opened Dektec application WinActivate("DekTec StreamXpress - Transport-Stream Player") Link to comment Share on other sites More sharing options...
rvn Posted July 23, 2010 Share Posted July 23, 2010 (edited) from help file "OnEvent functions are only called when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg is NOT used at all." @GeekOrGuru the real post is #3,,, is it?! Edited July 23, 2010 by rvn Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 23, 2010 Moderators Share Posted July 23, 2010 vishu,rvn has it - you are mixing OnEvent and GetMessage modes. You should only ever use one or the other mode in a script. Mixing them should only be done in exceptional circumstances - and you then should have lots of alarm bells going off asking why the circumstances are so exceptional and whether it would not be better to recast the code. So you have to make a choice:- 1. Add Opt("GUIOnEventMode", 1) at the beginning of the script, make sure you have a GUISetOnEvent/GUICtrlSetOnEvent for every GUI/control and get rid of the GUIGetMsg in your idle loop.- 2. Remove all GUISetOnEvent/GUICtrlSetOnEvent lines and make sure the GUIGetMsg in the idle loop covers all controls/events.Try and recast the script in a single mode - if it still does not work, come back and ask again. M23P.S. Nice try with the code tags - but you need to enclose them in [...], not <...> 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...
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