Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/19/2018 in all areas

  1. Bert

    ControlSend BUG

    Try using the control ID and not the title. Look at the examples in the help file and you will see how it works.
    1 point
  2. In case you need a version that keeps the sheets names unchanged, eventual duplicates will be shown with (2) appended to the sheet name. Also file names are sorted (useful) and sheet names will follow that order ; The test was made on 3 files : 1) 1st file : Sheet1a, Sheet1b, Sheet1c 2) 2nd file : Sheet2a, Sheet2b, Sheet2c 3) 3rd file : Sheet3a, Sheet3b, Sheet3c A little error checking in the script, for fun #include <Array.au3> #include <Excel.au3> #include <File.au3> #include <MsgBoxConstants.au3> $sFileSelectFolder = FileSelectFolder("select xlsx dir", @ScriptDir) If @error Then _Exit("FileSelectFolder", @error, @extended) $aFiles = _FileListToArray($sFileSelectFolder, "*.xlsx", 0, True) If @error Then _Exit("_FileListToArray", @error, @extended) _ArrayDisplay($aFiles, "Before sort") If @error Then _Exit("_ArrayDisplay - before sort", @error, @extended) _ArraySort($aFiles, 0, 1) ; 0 = Ascending order, 1 = index to start sorting If @error Then _Exit("_ArraySort", @error, @extended) _ArrayDisplay($aFiles, "After sort") If @error Then _Exit("_ArrayDisplay - after sort", @error, @extended) $oXL =_Excel_Open(False) If @error Then _Exit("_Excel_Open", @error, @extended) $oBook1 = _Excel_BookOpen($oXL , $aFiles[1]) If @error Then _Exit("_Excel_BookOpen file #1", @error, @extended) $aList = _Excel_SheetList($oBook1) If @error Then _Exit("_Excel_SheetList file #1", @error, @extended) $iIdx_Lastsheet = Ubound($aList) ; will be incremented after 1st copy, not b4 (+++) For $i = 2 to $aFiles[0] $oBookCpy = _Excel_BookOpen($oXL, $aFiles[$i]) If @error Then _Exit("_Excel_BookOpen file #" & $i, @error, @extended) $aList = _Excel_SheetList($oBookCpy) If @error Then _Exit("_Excel_SheetList file #" & $i, @error, @extended) For $n = 0 to Ubound($aList) - 1 _Excel_SheetCopyMove($oBookCpy, $n + 1, $oBook1, $iIdx_Lastsheet, False) If @error Then _Exit("_Excel_SheetCopyMove file #" & $i, @error, @extended) $iIdx_Lastsheet += 1 $oBook1.Sheets($iIdx_Lastsheet).Name = $aList[$n][0] Next _Excel_BookClose($oBookCpy, False) ; False = don't save If @error Then _Exit("_Excel_BookClose file #" & $i, @error, @extended) Next _Excel_BookSaveAs($oBook1, StringTrimRight($aFiles[1], 5) & "_MERGE.xlsx") If @error Then _Exit("_Excel_BookSaveAs" , @error, @extended) _Excel_BookClose($oBook1, False) ; False = don't save If @error Then _Exit("_Excel_BookClose file #1", @error, @extended) _Excel_Close($oXL, False, True) ; False = don't save (already done) . True = Force close If @error Then _Exit("_Excel_Close" , @error, @extended) ; ==================================================== Func _Exit($sError_msg, $iKeep_error, $iKeep_extended) MsgBox($MB_TOPMOST, "Error : " & $sError_msg , _ "@error = " & $iKeep_error & " @extended = " & $iKeep_extended) Exit EndFunc ; _Exit
    1 point
  3. I don't open files from the interwebs. Someone else will help you out, or please edit your comment and include the text. For toolbar controls use functions like: _guictrltoolbar_* or ControlCommand Check the help file on those.
    1 point
  4. #include <WindowsConstants.au3> #include <WinAPISysWin.au3> Local $hWnd = WinGetHandle("your window") $WS_EX_STYLE = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE) If BitAND($WS_EX_STYLE, $WS_EX_TOPMOST) Then     ConsoleWrite(" Window is on top ") Else     ConsoleWrite(" Window is not on top ") EndIf
    1 point
  5. Hello. I have 2 questions: 1) in registers under ddeexec key for .dwg files (for AutoCAD) says [open("%1")] Do I need to enclose the command in square brackets? 2) for some reason when I try use something like this: #include <DDEML.au3> #include <DDEMLClient.au3> $hData = _DDEMLClient_Execute("AutoCAD.r15.DDE", "system", 'open("D:\\test.dwg")') ConsoleWrite("_DDEMLClient_Execute()=" & $hData & ", error=" & @error & ", extended=" & @extended & @CRLF) It returns in console: Which looks fine, but AutoCAD shows bunch of question marks: ?????????? Is it possible that DDEML converts the command into UTF16 and AutoCAD 2002 doesn't support it? If so, is there a way send command in ASCII? Thank you. [EDIT] Answering my own questions: 1) yes, it must be enclosed in square brackets. 2) turned out it's the opposite, it was sending as plain text, but required in unicode format. My solution was to add 4th parameter in _DDEMLClient_Execute function: Func _DDEMLClient_Execute($szService, $szTopic, $szCommand, $wFmt = $CF_TEXT) Local $res = 0 Local $dwRes = _DdeInitialize("", BitOR($APPCMD_CLIENTONLY, $CBF_SKIP_ALLNOTIFICATIONS)) If $DMLERR_NO_ERROR <> $dwRes Then SetError($dwRes) Return $res EndIf Local $hszService = 0 If 0 < StringLen($szService) Then $hszService = _DdeCreateStringHandle($szService) Local $hszTopic = 0 If 0 < StringLen($szTopic) Then $hszTopic = _DdeCreateStringHandle($szTopic) Local $hConv = _DdeConnect($hszService, $hszTopic) If 0 <> $hConv Then Local $stData If _DDEML_CreateDataStruct($szCommand, $stData, $wFmt) Then Local $hData = _DdeCreateDataHandle($stData) $res = _DdeClientTransaction($XTYP_EXECUTE, $hConv, $hData) $stData = 0 EndIf _DdeDisconnect($hConv) EndIf If 0 <> $hszService Then _DdeFreeStringHandle($hszService) If 0 <> $hszTopic Then _DdeFreeStringHandle($hszTopic) _DdeUninitialize() Return $res EndFunc And then use this: #include <DDEML.au3> #include <DDEMLClient.au3> $hData = _DDEMLClient_Execute("AutoCAD.r15.DDE", "system", '[open("D:\test.dwg")]', $CF_UNICODETEXT) ConsoleWrite("_DDEMLClient_Execute()=" & $hData & ", error=" & @error & ", extended=" & @extended & @CRLF) (also no need escape backslashes in file path)
    1 point
  6. Just use the /MO (MergeOnly) and run Tidy to reformat it again. You should never maintain the output from au3stripper, just use it to run the script, and maintain the original master. ... but why not compiling the sources as A3X and run it with AutoIt3? Jos
    1 point
  7. jolumaoj, Welcome to the AutoIt forum. Yes it is quite possible - as you can see here: #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> ; Mouse coords relative to GUI client area Opt("MouseCoordMode", 2) ; Set target coords Global $iTgt_Left = 10, $iTgt_Right = 210, $iTgt_Top = 10, $iTgt_Bot = 110 ; Create GUI $hGUI = GUICreate("Test", 300, 200) $cTarget = GUICtrlCreateLabel("", $iTgt_Left, $iTgt_Top, $iTgt_Right - $iTgt_Left, $iTgt_Bot - $iTgt_Top, $SS_BLACKFRAME) GUICtrlSetState(-1, $GUI_DISABLE) $cLabel = GUICtrlCreateLabel("Move me", 10, 150, 60, 20) GUICtrlSetBkColor(-1, 0x00FF00) $cButton = GUICtrlCreateButton("Me too", 110, 150, 80, 23) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN ; If the mouse button is pressed - get info about where $cInfo = GUIGetCursorInfo($hGUI) ; Is it over a control $iControl = $cInfo[4] Switch $iControl ; If it is a control we want to move Case $cLabel, $cButton ; Work out offset of mouse on control $aPos = ControlGetPos($hGUI, "", $iControl) $iSubtractX = $cInfo[0] - $aPos[0] $iSubtractY = $cInfo[1] - $aPos[1] ; And then move the control until the mouse button is released Do $cInfo = GUIGetCursorInfo($hGUI) ControlMove($hGUI, "", $iControl, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY) Until Not $cInfo[2] ; See if the mouse was released over the target $aMPos = MouseGetPos() If $aMPos[0] > $iTgt_Left And $aMPos[0] < $iTgt_Right Then If $aMPos[1] > $iTgt_Top And $aMPos[1] < $iTgt_Bot Then Switch $iControl Case $cLabel $sItem = "label" Case $cButton $sItem = "button" EndSwitch MsgBox(0, "Info", "Over target with " & $sItem) EndIf EndIf EndSwitch EndSwitch WEnd Please ask if you have any questions. M23
    1 point
  8. jchd

    Modified _FileCountLines()

    I believe the following version is about as fast as pure AutoIt can be and it doesn't have any file size or memory limitation. By default, it simply counts linefeeds only (this is compatible with both traditional Unix-like [LF] and DOS-Windows [CRLF] conventions) using a 8Mb buffer, which should cope with any decent PC RAM and hard disk or SSD buffer. Adjust buffer size to vary results sligthly. One can change the line counting behavior by passing a non-zero second argument. It then counts carriage-returns only (suitable for traditional Mac text files convention [CR]). Func _FileCountLines($sFilePath, $CRonly = 0) Local $hFile = FileOpen($sFilePath) If $hFile = -1 Then Return SetError(1, 0, 0) Local $iLineCount = 0, $sBuffer, $iReadBytes, $bDone Local Const $BUFFER_SIZE = 8 * 1024 * 1024 Local $sTermination = @LF If $CRonly Then $sTermination = @CR Do $sBuffer = FileRead($hFile, $BUFFER_SIZE) $bDone = (@extended <> $BUFFER_SIZE) StringRegExpReplace($sBuffer, $sTermination, "") $iLineCount += @extended Until $bDone If FileGetPos($hFile) > 0 Then FileSetPos($hFile, -1, 1) If FileRead($hFile, 1) <> $sTermination Then $iLineCount += 1 EndIf FileClose($hFile) Return $iLineCount EndFunc ;==>_FileCountLines Edit: fixed empty file case. Oops.
    1 point
  9. Hi remin If you study the following scripts (don't remember where I found them, wiki probably) it may give you ideas to solve your problem. First with GuiGetMsg : #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; example of how to manage two GUIs simultaneously using the "advanced" parameter with GUIGetMsg : Yes ! (MessageLoop mode) ; a single While...WEnd loop which distinguishes between the two GUIs, both GUIs and their controls remain active and we stay ; in the main idle loop while we wait Global $g_hGUI2 = 9999 ; Predeclare this variable with dummy value to prevent firing the Case statement, only for GUI2 this time Global $g_idButton3 gui1() Func gui1() Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100) Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) Local $idButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30) GUISetState() Local $aMsg While 1 $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array Switch $aMsg[1] ; check which GUI sent the message Case $hGUI1 Switch $aMsg[0] ; Now check for the messages for $hGUI1 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we exit <<<<<<<<<<<<<<< ExitLoop Case $idButton1 MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1") Case $idButton2 GUICtrlSetState($idButton2, $GUI_DISABLE) gui2() EndSwitch Case $g_hGUI2 Switch $aMsg[0] ; Now check for the messages for $g_hGUI2 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we just delete the GUI <<<<<<<<<<<<<<< GUIDelete($g_hGUI2) GUICtrlSetState($idButton2, $GUI_ENABLE) Case $g_idButton3 MsgBox($MB_OK, "MsgBox", "Test from Gui 2") EndSwitch EndSwitch WEnd EndFunc ;==>gui1 Func gui2() $g_hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350) $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) GUISetState() EndFunc ;==>gui2 Then, as suggested by Careca, with On Event Mode : #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; Coders using OnEvent mode do not usually find the same problem with multiple GUIs as they can code separate functions ; for each $GUI_EVENT_CLOSE as shown in this example. Good (OnEvent mode) Opt("GUIOnEventMode", 1) Global $g_hGUI2, $g_idButton2 ; Predeclare these variables gui1() Func gui1() Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main") ; Run this function when the main GUI [X] is clicked Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "On_Button1") $g_idButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30) GUICtrlSetOnEvent(-1, "On_Button2") GUISetState() While 1 Sleep(10) WEnd EndFunc ;==>gui1 Func gui2() $g_hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Secondary") ; Run this function when the secondary GUI [X] is clicked Local $idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "On_Button3") GUISetState() EndFunc ;==>gui2 Func On_Close_Main() Exit EndFunc ;==>On_Close_Main Func On_Close_Secondary() GUIDelete($g_hGUI2) GUICtrlSetState($g_idButton2, $GUI_ENABLE) EndFunc ;==>On_Close_Secondary Func On_Button1() MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1") EndFunc ;==>On_Button1 Func On_Button2() GUICtrlSetState($g_idButton2, $GUI_DISABLE) gui2() EndFunc ;==>On_Button2 Func On_Button3() MsgBox($MB_OK, "MsgBox 2", "Test from Gui 2") EndFunc ;==>On_Button3 Good luck
    0 points
  10. Send is one have the hackiest ways to automate something. how can you expect to automate something reliably if you can't verify your action was received (rhetorical). maybe your window was not ready to accept input, maybe your network went down temporarily, maybe a popup became active. there is too many what ifs in a windows environment to ever use ONLY *send reliably. this is not a bug, it's a flaw in your scripting
    0 points
  11. Jos

    ControlSend BUG

    I am seriously wondering what you are expecting as reply to your posts as they don't contain any information what you are doing other than screwing a working script? When you want any serious assistance you open a new thread in the support forum providing enough details about what you are doing and where things go wrong. Jos
    0 points
×
×
  • Create New...