lorenkinzel Posted January 14, 2014 Posted January 14, 2014 (edited) I've used 2 different restart scripts from the forums with no trouble at all; until now. This one is in on event, with a button to trigger "_ScriptRestart". That works fine, but the keyboard enter button triggers it as well. By now you may have guessed that I can not figure out why Enter triggers it. Any Ideas? Button in question is on line 39 & _ScriptRestart (Yashied) is at the bottom of script. expandcollapse popup#cs ---------------------------------------------------------------------------- Beginnings of another helper system for the GS series. To do: move multiplier inputs so you can tab-thru. Numeric rounding in "populateGrids" func. Determine appropriate # of items, grids; remove blank areas from GUI. 1) Find out WHY "enter" triggers the "_ScriptRestart" func. Get it to open at upper-right corner of screen. #ce ---------------------------------------------------------------------------- #OnAutoItStartRegister "OnAutoItStart" #include <GUIConstantSex.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <Excel.au3> Opt("GUIOnEventMode", 1) Global $inputType[12] Global $input1Num[12] Global $input2Num[12] Global $input3Num[12] Global $input4Num[12] Global $input5Num[12] Global $inputQty[12] Global $__Restart = False Global $oExcel = ObjGet("", "Excel.Application"); Get an EXISTING Excel Object (book open before script) $theForm = GUICreate("Entry", 623, 600, 192, 124) GUISetBkColor(0x8c6928, $theForm) WinSetOnTop("Entry", "", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "xIt") Func xIt() Exit EndFunc ;==>xIt $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ;Initialize a COM error handler(that I fail to understand. $reStartButton = GUICtrlCreateButton("R", 1, 1, 15, 15) GUICtrlSetOnEvent($reStartButton, "_ScriptRestart");<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<button in question Function is at the bottom GUICtrlSetBkColor($reStartButton, 0x00F000) GUICtrlSetTip($reStartButton, "restart") $multiplierLabel = GUICtrlCreateLabel("L.F./# times", 550, 5, 75, 18) ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>mat type For $y = 0 To 11 $inputType[$y] = GUICtrlCreateInput("", 1, ($y) * 25 + 30, 145, 21);make 12 inputs GUICtrlSetBkColor($inputType[$y], 0xC0D0FF) Next ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Qty per foot For $y = 0 To 11 $inputQty[$y] = GUICtrlCreateInput("", 151, ($y) * 25 + 30, 80, 21) GUICtrlSetBkColor($inputQty[$y], 0xC0D0FF) Next ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>multiply qyt per foot to each grid $qtyMultiplyButton = GUICtrlCreateButton("populate", 151, 340, 55, 21) GUICtrlSetOnEvent($qtyMultiplyButton, "populate") ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Qty1 $grid1Multiplier = GUICtrlCreateInput("", 240, 1, 55, 21);>>>>>>>>>>>>>need to relocate these so you can tab thru them GUICtrlSetBkColor($grid1Multiplier, 0xC0D0FF) For $y = 0 To 11 $input1Num[$y] = GUICtrlCreateInput("", 240, ($y) * 25 + 30, 55, 21) Next ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Qty2 $grid2Multiplier = GUICtrlCreateInput("", 300, 1, 55, 21) GUICtrlSetBkColor($grid2Multiplier, 0xC0D0FF) For $y = 0 To 11 $input2Num[$y] = GUICtrlCreateInput("", 300, ($y) * 25 + 30, 55, 21) Next ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Qty3 $grid3Multiplier = GUICtrlCreateInput("", 360, 1, 55, 21) GUICtrlSetBkColor($grid3Multiplier, 0xC0D0FF) For $y = 0 To 11 $input3Num[$y] = GUICtrlCreateInput("", 360, ($y) * 25 + 30, 55, 21) Next ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Qty4 $grid4Multiplier = GUICtrlCreateInput("", 420, 1, 55, 21) GUICtrlSetBkColor($grid4Multiplier, 0xC0D0FF) For $y = 0 To 11 $input4Num[$y] = GUICtrlCreateInput("", 420, ($y) * 25 + 30, 55, 21) Next ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Qty5 $grid5Multiplier = GUICtrlCreateInput("", 480, 1, 55, 21) GUICtrlSetBkColor($grid5Multiplier, 0xC0D0FF) For $y = 0 To 11 $input5Num[$y] = GUICtrlCreateInput("", 480, ($y) * 25 + 30, 55, 21) Next ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>navigation instruments $bookNameInput = GUICtrlCreateLabel("", 1, 520, 283, 21) $activeRowNumInput = GUICtrlCreateLabel("active row #", 1, 545, 80, 21) $activeColumnNumInput = GUICtrlCreateLabel("active column #", 1, 570, 80, 21) $row_colSplitButton = GUICtrlCreateButton("get excel cell", 120, 579, 121, 21) GUICtrlSetOnEvent($row_colSplitButton, "splitCellNum") ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>write item types to excel $writeButton = GUICtrlCreateButton("write data", 10, 340, 121, 21) GUICtrlSetOnEvent($writeButton, "writeToExcel") ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>write quantities to excel $grid1Button = GUICtrlCreateButton("write", 240, 340, 55, 21) GUICtrlSetOnEvent($grid1Button, "WriteGrid1") $grid2Button = GUICtrlCreateButton("write", 300, 340, 55, 21) GUICtrlSetOnEvent($grid2Button, "WriteGrid2") $grid3Button = GUICtrlCreateButton("write", 360, 340, 55, 21) GUICtrlSetOnEvent($grid3Button, "WriteGrid3") $grid4Button = GUICtrlCreateButton("write", 420, 340, 55, 21) GUICtrlSetOnEvent($grid4Button, "WriteGrid4") $grid5Button = GUICtrlCreateButton("write", 480, 340, 55, 21) GUICtrlSetOnEvent($grid5Button, "WriteGrid5") ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>section visual seperators (black lines)GUICtrlCreateGraphic $line = GUICtrlCreateLabel("", 1, 370, 621, 4) GUICtrlSetBkColor($line, 0x000000) $line2 = GUICtrlCreateLabel("", 147, 370, 4, 60) GUICtrlSetBkColor($line2, 0x000000) $line3 = GUICtrlCreateLabel("", 1, 430, 150, 4) GUICtrlSetBkColor($line3, 0x000000) ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> .ini items $nuIniInput = GUICtrlCreateInput("", 1, 380, 145, 21);enter name of new .ini(assembly) $nuIniButton = GUICtrlCreateButton("save as new assembly", 1, 405, 145, 21);save assembly GUICtrlSetTip($nuIniButton, "enter name first") GUICtrlSetOnEvent($nuIniButton, "saveNuAssembly") $loadAssemblyButton = GUICtrlCreateButton("load saved assembly", 160, 380, 145, 21);Load existing assembly GUICtrlSetOnEvent($loadAssemblyButton, "loadAssembly") $wintitle = WinGetTitle("Microsoft Excel") GUICtrlSetData($bookNameInput, $wintitle) GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func MyErrFunc();by others Local $err = $oMyError.number If $err = 0 Then $err = -1 SetError($err) EndFunc ;==>MyErrFunc Func splitCellNum();get R1C1 address of selected cell If GUICtrlRead($bookNameInput) <> "" Then;keeps it from crashing if excel is not open While WinExists($wintitle) $Row = $oExcel.ActiveCell.Row $Column = $oExcel.ActiveCell.Column GUICtrlSetData($activeRowNumInput, $Row) GUICtrlSetData($activeColumnNumInput, $Column) Sleep(100) ExitLoop WEnd EndIf EndFunc ;==>splitCellNum Func writeToExcel();the item type inputs splitCellNum() Sleep(100) GUICtrlSetBkColor($writeButton, 0xFFD0B0) Local $Row = Number(GUICtrlRead($activeRowNumInput)) Local $rowNum = $Row Local $Column = Number(GUICtrlRead($activeColumnNumInput)) For $y = 0 To 11 _ExcelWriteCell($oExcel, GUICtrlRead($inputType[$y]), $rowNum, $Column) Sleep(500) $rowNum += 1 Next GUICtrlSetStyle($writeButton, 0) EndFunc ;==>writeToExcel Func WriteGrid1();write the quantity inputs to excel splitCellNum() Sleep(100) GUICtrlSetBkColor($grid1Button, 0xFFD0B0); so you know when the function is finished Local $Row = Number(GUICtrlRead($activeRowNumInput)) Local $rowNum = $Row Local $Column = Number(GUICtrlRead($activeColumnNumInput)) For $y = 0 To 11 _ExcelWriteCell($oExcel, GUICtrlRead($input1Num[$y]), $rowNum, $Column) Sleep(10) $rowNum += 1 Next GUICtrlSetStyle($grid1Button, 0);the function is finished. The button is no longer orange. EndFunc ;==>WriteGrid1 Func WriteGrid2() splitCellNum() Sleep(100) GUICtrlSetBkColor($grid2Button, 0xFFD0B0) Local $Row = Number(GUICtrlRead($activeRowNumInput)) Local $rowNum = $Row Local $Column = Number(GUICtrlRead($activeColumnNumInput)) For $y = 0 To 11 _ExcelWriteCell($oExcel, GUICtrlRead($input2Num[$y]), $rowNum, $Column) Sleep(10) $rowNum += 1 Next GUICtrlSetStyle($grid2Button, 0) EndFunc ;==>WriteGrid2 Func WriteGrid3() splitCellNum() Sleep(100) GUICtrlSetBkColor($grid3Button, 0xFFD0B0) Local $Row = Number(GUICtrlRead($activeRowNumInput)) Local $rowNum = $Row Local $Column = Number(GUICtrlRead($activeColumnNumInput)) For $y = 0 To 11 _ExcelWriteCell($oExcel, GUICtrlRead($input3Num[$y]), $rowNum, $Column) Sleep(10) $rowNum += 1 Next GUICtrlSetStyle($grid3Button, 0) EndFunc ;==>WriteGrid3 Func WriteGrid4() splitCellNum() Sleep(100) GUICtrlSetBkColor($grid4Button, 0xFFD0B0) Local $Row = Number(GUICtrlRead($activeRowNumInput)) Local $rowNum = $Row Local $Column = Number(GUICtrlRead($activeColumnNumInput)) For $y = 0 To 11 _ExcelWriteCell($oExcel, GUICtrlRead($input4Num[$y]), $rowNum, $Column) Sleep(10) $rowNum += 1 Next GUICtrlSetStyle($grid4Button, 0) EndFunc ;==>WriteGrid4 Func WriteGrid5() splitCellNum() Sleep(100) GUICtrlSetBkColor($grid5Button, 0xFFD0B0) Local $Row = Number(GUICtrlRead($activeRowNumInput)) Local $rowNum = $Row Local $Column = Number(GUICtrlRead($activeColumnNumInput)) For $y = 0 To 11 _ExcelWriteCell($oExcel, GUICtrlRead($input5Num[$y]), $rowNum, $Column) Sleep(10) $rowNum += 1 Next GUICtrlSetStyle($grid5Button, 0) EndFunc ;==>WriteGrid5 Func populate();allows you to enter formula rather than just a number For $y = 0 To 11 GUICtrlSetData($inputQty[$y], Execute(GUICtrlRead($inputQty[$y]))); Could have risks; but given the usage, unlikely. Next populateGrids() EndFunc ;==>populate Func populateGrids();Multiply item/L.F. by the footage in each grid Local $footage1 = Number(GUICtrlRead($grid1Multiplier)) For $y = 0 To 11 If (Number(GUICtrlRead($inputQty[$y])) * $footage1) > 0 Then GUICtrlSetData($input1Num[$y], Number(GUICtrlRead($inputQty[$y])) * $footage1) EndIf Next Local $footage2 = Number(GUICtrlRead($grid2Multiplier)) For $y = 0 To 11 If (Number(GUICtrlRead($inputQty[$y])) * $footage2) > 0 Then GUICtrlSetData($input2Num[$y], Number(GUICtrlRead($inputQty[$y])) * $footage2) EndIf Next Local $footage3 = Number(GUICtrlRead($grid3Multiplier)) For $y = 0 To 11 If (Number(GUICtrlRead($inputQty[$y])) * $footage3) > 0 Then GUICtrlSetData($input3Num[$y], Number(GUICtrlRead($inputQty[$y])) * $footage3) EndIf Next Local $footage4 = Number(GUICtrlRead($grid4Multiplier)) For $y = 0 To 11 If (Number(GUICtrlRead($inputQty[$y])) * $footage4) > 0 Then GUICtrlSetData($input4Num[$y], Number(GUICtrlRead($inputQty[$y])) * $footage4) EndIf Next Local $footage5 = Number(GUICtrlRead($grid5Multiplier)) For $y = 0 To 11 If (Number(GUICtrlRead($inputQty[$y])) * $footage5) > 0 Then GUICtrlSetData($input5Num[$y], Number(GUICtrlRead($inputQty[$y])) * $footage5) EndIf Next EndFunc ;==>populateGrids Func saveNuAssembly(); save the assembly as an .ini (I chose the ext .ass) $name = GUICtrlRead($nuIniInput) For $y = 0 To 11 IniWrite(@ScriptDir & "\" & $name & ".ass", $y, "item", GUICtrlRead($inputType[$y]));.ini IniWrite(@ScriptDir & "\" & $name & ".ass", $y, "qty", GUICtrlRead($inputQty[$y])) Next EndFunc ;==>saveNuAssembly Func loadAssembly(); load an existing assembly into the "item" & "qty" inputs $location = @ScriptDir $openedFile = FileOpenDialog("select assembly", $location, "(*.ass)", 5) For $y = 0 To 11 GUICtrlSetData($inputType[$y], IniRead($openedFile, $y, "item", 0)) GUICtrlSetData($inputQty[$y], IniRead($openedFile, $y, "qty", 0)) Next EndFunc ;==>loadAssembly Func _ScriptRestart();_ScriptRestart($fExit = 1) Yashied Local $fExit = 1 Local $Pid If Not $__Restart Then If @compiled Then $Pid = Run(@ScriptFullPath & ' ' & $CmdLineRaw, @ScriptDir, Default, 1) Else $Pid = Run(@AutoItExe & ' "' & @ScriptFullPath & '" ' & $CmdLineRaw, @ScriptDir, Default, 1) EndIf If @error Then Return SetError(@error, 0, 0) EndIf StdinWrite($Pid, @AutoItPID) EndIf $__Restart = 1 If $fExit Then Sleep(50) Exit EndIf Return 1 EndFunc ;==>_ScriptRestart Func OnAutoItStart() Sleep(50) Local $Pid = ConsoleRead(1) If @extended Then While ProcessExists($Pid) Sleep(100) WEnd EndIf EndFunc ;==>OnAutoItStart Edited January 14, 2014 by lorenkinzel
Danp2 Posted January 14, 2014 Posted January 14, 2014 Just a WAG, but does the button have focus when you press enter? If so, that would explain the behavior you are seeing. Latest Webdriver UDF Release Webdriver Wiki FAQs
lorenkinzel Posted January 14, 2014 Author Posted January 14, 2014 Pretty good WAG. I did not think that it had focus, but then I remembered warnings from all the MVPs about (the damned) colored buttons. Got rid of the color & all is well. I'll just need to make the button a little bigger. THanks much.
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