Leaderboard
Popular Content
Showing content with the highest reputation on 08/27/2013 in all areas
-
1 point
-
You can use this function: Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface) Local Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods $tagInterface = $tagIUnknown & $tagInterface Local Const $PTR_SIZE = DllStructGetSize(DllStructCreate("ptr")) ; Below line really simple even though it looks super complex. It's just written weird to fit one line, not to steal your eyes Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace($tagInterface, "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "variant*", "ptr"), "hresult", "long"), "bstr", "ptr"), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams ; Allocation. Read http://msdn.microsoft.com/en-us/library/ms810466.aspx to see why like this (object + methods): $tInterface = DllStructCreate("ptr[" & $iUbound + 1 & "]") If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams DllStructSetData($tInterface, 1, DllCallbackGetPtr(DllCallbackRegister($sMethod, $sRet, $sParams)), $i + 2) ; Freeing is left to AutoIt. Next DllStructSetData($tInterface, 1, DllStructGetPtr($tInterface) + $PTR_SIZE) ; Interface method pointers are actually pointer size away Return ObjCreateInterface(DllStructGetPtr($tInterface), "", $tagInterface, False) ; and first pointer is object pointer that's wrapped EndFunc ...And you would use it like this: $objUIAutomation = ... ;~ Focus Changed Handler Global $tFCEHandler Global $oFCEHandler = ObjectFromTag("_MyHandler_", $dtagIUIAutomationFocusChangedEventHandler, $tFCEHandler) $objUIAutomation.AddFocusChangedEventHandler(0, $oFCEHandler()) ;... the rest of your code ... $objUIAutomation.RemoveAllEventHandlers() ; The End ; Handler methods. "_MyHandler_" is the specified prefix: Func _MyHandler_QueryInterface($pSelf, $pRIID, $pObj) Local $tStruct = DllStructCreate("ptr", $pObj) Switch _WinAPI_StringFromGUID($pRIID) Case $sIID_IUnknown, $sIID_IUIAutomationFocusChangedEventHandler Case Else ConsoleWrite(@CRLF) Return 0x80004002 ; E_NOINTERFACE EndSwitch DllStructSetData($tStruct, 1, $pSelf) Return 0 ; S_OK EndFunc Func _MyHandler_AddRef($pSelf) #forceref $pSelf Return 1 EndFunc Func _MyHandler_Release($pSelf) #forceref $pSelf Return 1 EndFunc Func _MyHandler_HandleFocusChangedEvent($pSelf, $pElem) #forceref $pSelf If $pElem Then Local $oElem = ObjCreateInterface($pElem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) Local $sFocused $oElem.CurrentClassName($sFocused) ConsoleWrite(">>> Somebody is changing the focus to: " & $sFocused & @CRLF) EndIf Return 0 ; S_OK EndFunc1 point
-
incepator, Sorry - use the Beta or run this with 3.3.8.1: #include <GUIConstantsEx.au3> #include <GuiListView.au3> Global $aData[7] = ["1|test", "2|one", "3|test", "4|test", "5|fb", "6|fb", "7|night"] Global $aUnique[UBound($aData) + 1] = [0] $hGUI = GUICreate("Form1", 500, 500) $cListView = GUICtrlCreateListView("nr|List", 10, 10, 450, 400) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250) For $i = 0 To UBound($aData) - 1 $aSplit = StringSplit($aData[$i], "|") $sData = $aSplit[2] _ArraySearch($aUnique, $sData, 1) If @error Then $aUnique[0] += 1 $aUnique[$aUnique[0]] = $sData GUICtrlCreateListViewItem($aData[$i], $cListView) EndIf Next $Input1 = GUICtrlCreateInput("", 160, 424, 121, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd M231 point
-
msgbox when clock time = specified time
Alexxander reacted to Melba23 for a topic
alexander95, Rather than feeling sorry for yourself, learn from the above and try some basic errorchecking yourself before posting next time. For example, if you have a comparison that is not working, make sure that you are comparing things which are alike - if a file operation does not work, check the path that you are passing to it. etc, etc. It is experience that suggests where to look to find problems - so build up your own experience level, simple really. M231 point -
msgbox when clock time = specified time
Alexxander reacted to Melba23 for a topic
alexander95, Yes. Try adding these 2 lines and see if you can see it as well: func but() ConsoleWrite(GUICtrlRead($date) & @CRLF) ConsoleWrite(_Now() & @CRLF) do Sleep (1000) Until _Now() = GUICtrlRead($date) MsgBox(0, "", "matched") EndFunc Did the light bulb illuminate? M231 point -
Delete duplicate in ListView
incepator reacted to michaelslamet for a topic
This is one of the many ways to do it: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 213, 209, 456, 343) $ListView1 = GUICtrlCreateListView("nr|name", 0, 0, 210, 158) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50) GUICtrlCreateListViewItem("1|test", $ListView1) GUICtrlCreateListViewItem("2|one", $ListView1) GUICtrlCreateListViewItem("3|test", $ListView1) GUICtrlCreateListViewItem("4|test", $ListView1) GUICtrlCreateListViewItem("5|fb", $ListView1) GUICtrlCreateListViewItem("6|fb", $ListView1) GUICtrlCreateListViewItem("7|night", $ListView1) $Button1 = GUICtrlCreateButton("Del Dup", 24, 168, 107, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $all[200] While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $n = 0 to _GUICtrlListView_GetItemCount($ListView1) - 1 $aaa = StringSplit(_GUICtrlListView_GetItemTextString($ListView1, $n),"|") $all[$n] = $aaa[2] Next _ArrayDupes($all, 1, 0) ; delete duplicate array content For $i = UBound($all) - 1 To 0 Step - 1 ; delete array element if array element = "" (blank) If $all[$i] = "" Then _ArrayDelete($all, $i) Next _GUICtrlListView_DeleteAllItems($ListView1) ; delete all of the ListView content For $n = 0 to Ubound($all) - 1 ; display a new ListView content GUICtrlCreateListViewItem($n + 1 & "|" & $all[$n], $ListView1) Next EndSwitch WEnd ;=============================================================================== ; ; Description: _ArrayDupes; deletes duplicates in an Array 1D ; Syntax: _ArrayDupes(ByRef $ar_Array) ; Parameter(s): $ar_Array = 1d Array ; Requirement(s): None ; Return Value(s): On Success - Returns array of duplicates; options for unique or details of all ; - byref Returns a sorted array with no duplicates ; On Failure - ; @Error=1 P ; @Error=2 ; ; Author(s): randallc ;=============================================================================== Func _ArrayDupes(ByRef $arrItemsF, $iDelete = 0, $iDetails = 0) local $timerstamp1 = TimerInit() If @OSTYPE = "WIN32_WINDOWS" Then Return 0 If not IsArray($arrItemsF) then Return 0 Local $arrItems = $arrItemsF Local $i = 0, $k = 0, $objDictionary = ObjCreate("Scripting.Dictionary"), $arrItemsDupes[UBound($arrItems)] Local $objDictDupes = ObjCreate("Scripting.Dictionary") For $strItem In $arrItems If Not $objDictionary.Exists($strItem) Then $objDictionary.Add($strItem, $strItem) Else If $iDetails Then $arrItemsDupes[$k] = $strItem & "|Dupes|" & $i Else If Not $objDictDupes.Exists($strItem) Then $objDictDupes.Add($strItem, $strItem) EndIf $k += 1 EndIf $i += 1 Next ReDim $arrItems[$objDictionary.Count ] If $k = 0 Then ReDim $arrItemsDupes[1 ] If $k > 0 Then ReDim $arrItemsDupes[$k ] $i = 0 If $iDelete Then For $strKey In $objDictionary.Keys $arrItems[$i] = $strKey $i += 1 Next $arrItemsF = $arrItems ;array deleted dupes EndIf $i = 0 If Not $iDetails Then For $strKey In $objDictDupes.Keys $arrItemsDupes[$i] = $strKey $i += 1 Next If $i > 0 Then ReDim $arrItemsDupes[$i] EndIf ConsoleWrite("Total Time= " & Round(TimerDiff($timerstamp1)) & "" & @TAB & " msec" & @LF) Return $arrItemsDupes EndFunc ;==>_ArrayDupes1 point -
drbyte, The concept of the solution for your problem is the same like what we discuss before. Use _arraysearch to check whether there is a match. If there is mark X on the corresponding column. You can refer to my code below: #include <File.au3> #include <Array.au3> #include <Excel.au3> ; ------------------------------------------------------------------------------------ ; create pdf files in @scriptdir \test\ for testing ; ------------------------------------------------------------------------------------ Local $result[16] $result[0] = "Could be any name - ABCD001.pdf" $result[1] = "Could be any name - ABCD003.pdf" $result[2] = "Could be any name - ABCD005.pdf" $result[3] = "Could be any name - ABCD007.pdf" $result[4] = "Could be any name - ABCD009.pdf" $result[5] = "material-1a_124567.pdf" $result[6] = "material-1b_12345_589752467.pdf" $result[7] = "material-1c_12345_nesting.pdf" $result[8] = "material-1d_us_04030-2010-09-03.pdf" $result[9] = "material-1e_us_Certificaat.pdf" $result[10] = "material-1f_z35_SL1020_01.pdf" $result[11] = "material-1g_harden_W1305050.pdf" $result[12] = "material-1h_veredelen_SL1025_02.pdf" $result[13] = "material-1k_painting.pdf" $result[14] = "material-1i_ndt_RM0199.pdf" $result[15] = "material-1j_ndt_Certificaat.pdf" For $1 = 0 To UBound($result) - 1 FileOpen(@ScriptDir & '\test\' & $result[$1], 10) Next ; end creation pdf file's ; list all .pdf type files from a specific directory $atemp_Files = _FileListToArray(@ScriptDir & '\test\', '*.pdf', 1) _ArrayDisplay($atemp_Files, "Directory loaded") ; Remove all file names with "material-" in the pdf file For $i = UBound($atemp_Files) - 1 To 0 Step -1 If StringInStr($atemp_Files[$i], "material-", 0) Then _ArrayDelete($atemp_Files, $i) EndIf Next _ArrayDisplay($atemp_Files, "Material pdf's removed") ; create final result array with 2 dimensions Local $aFiles[UBound($atemp_Files)][2] ; populate 1ST dimension of final result array with complete file name (not path) For $1 = 0 To UBound($atemp_Files) - 1 $aFiles[$1][0] = $atemp_Files[$1] Next ; populate 2ND dimension of final result array with stripped out file name Local $aTmp For $1 = 1 To UBound($aFiles) - 1 $aTmp = StringRegExp($aFiles[$1][0], '[a-zA-Z]{1,4}[0-9]{1,3}', 3) If IsArray($aTmp) Then $aFiles[$1][1] = $aTmp[0] Next _ArrayDisplay($aFiles, "2nd Array filled") _ArrayDelete($aFiles, 0) ;this is just to let the workbook looks like your snapshot example Local $oExcel=_ExcelBookNew() _ExcelWriteCell($oExcel,"Number",1,1) _ExcelWriteCell($oExcel,"Report",1,2) _ExcelWriteCell($oExcel,"ABCD001",2,1) $oExcel.Range("A2").Select $oExcel.Selection.AutoFill($oExcel.Range("A2:A21"), 0) ; this is the code for matching with the column A with the array you got. For $i=0 to 19; based on the example you give: ABCD001 ~ ABCD020 if _arraysearch($aFiles,$oExcel.Cells($i+2,1).value,0,0,1,2,1,1) <>-1 Then _ExcelWriteCell($oExcel,"X",$i+2,2) EndIf Next1 point
-
I do not know if I have this right ... See if this is what you want ... #include <File.au3> #include <Array.au3> #include <Excel.au3> ; ------------------------------------------------------------------------------------ ; create pdf files in @scriptdir \test\ for testing ; ------------------------------------------------------------------------------------ Local $result[16] $result[0] = "Could be any name - ABCD001.pdf" $result[1] = "Could be any name - ABCD003.pdf" $result[2] = "Could be any name - ABCD005.pdf" $result[3] = "Could be any name - ABCD007.pdf" $result[4] = "Could be any name - ABCD009.pdf" $result[5] = "material-1a_124567.pdf" $result[6] = "material-1b_12345_589752467.pdf" $result[7] = "material-1c_12345_nesting.pdf" $result[8] = "material-1d_us_04030-2010-09-03.pdf" $result[9] = "material-1e_us_Certificaat.pdf" $result[10] = "material-1f_z35_SL1020_01.pdf" $result[11] = "material-1g_harden_W1305050.pdf" $result[12] = "material-1h_veredelen_SL1025_02.pdf" $result[13] = "material-1k_painting.pdf" $result[14] = "material-1i_ndt_RM0199.pdf" $result[15] = "material-1j_ndt_Certificaat.pdf" For $1 = 0 To UBound($result) - 1 FileOpen(@ScriptDir & '\test\' & $result[$1], 16) Next ; end creation pdf file's ; list all .pdf type files from a specific directory $atemp_Files = _FileListToArray(@ScriptDir & '\test\', '*.pdf', 1) _ArrayDisplay($atemp_Files, "Directory loaded") ; Remove all file names with "material-" in the pdf file For $i = UBound($atemp_Files) - 1 To 0 Step -1 If StringInStr($atemp_Files[$i], "material-", 0) Then _ArrayDelete($atemp_Files, $i) EndIf Next _ArrayDisplay($atemp_Files, "Material pdf's removed") ; create final result array with 2 dimensions Local $aFiles[UBound($atemp_Files)][2] ; populate 1ST dimension of final result array with complete file name (not path) For $1 = 0 To UBound($atemp_Files) - 1 $aFiles[$1][0] = $atemp_Files[$1] Next ; populate 2ND dimension of final result array with stripped out file name Local $aTmp For $1 = 1 To UBound($aFiles) - 1 $aTmp = StringRegExp($aFiles[$1][0], '[a-zA-Z]{1,4}[0-9]{1,3}', 3) If IsArray($aTmp) Then $aFiles[$1][1] = $aTmp[0] Next _ArrayDisplay($aFiles, "2nd Array filled") ; ------------------------------------------------------------------------------------ ; iterate array looking for element with "paint" in the name ; ------------------------------------------------------------------------------------ $oExcel = _ExcelBookOpen(@ScriptDir & "\test\FileExcel.xlsx", 0) For $1 = 1 To UBound($aFiles) - 1 For $i = 2 To 21 If $aFiles[$1][1] = $oExcel.Sheets("Folha1").Range("A" & $i).Value Then $oExcel.Sheets("Folha1").Range("B" & $i).Value = StringUpper("x") EndIf Next Next _ExcelBookClose($oExcel) _ArrayDelete($aFiles, 0) MsgBox(0, "", "ConcluĂdo", 2) Exit1 point
-
I've added AutoItX3_DLL.cs to the beta. It contains the DLLImports and some easier to use wrappers. The DLLImports are set as private with only the wrappers being visible as I intend for all use/intellisense to be done through the wrappers - I just have to code them all up... The wrappers currently implemented match the speed of development of the PowerShell Cmdlets because I'm doing them at the same time.1 point
-
Line Number in message box display
czardas reacted to AdmiralAlkex for a topic
To automatically get the line number you can set @ScriptLineNumber as a default value for a optional function parameter, then the function will know when it was called from. Example: Local $stringinput = "test abc" _MsgBox("The value for $stringinput is not as expected == " & $stringinput) _MsgBox("The value for $stringinput is not as expected == " & $stringinput) _MsgBox("The value for $stringinput is not as expected == " & $stringinput) Func _MsgBox($sText, $sTitle = @ScriptLineNumber) MsgBox(0, "-" & $sTitle & "-", $sText) EndFunc1 point -
Skin UDF
BinaryBrother reacted to BrewManNH for a topic
2 problems with this, one you're using AdFly to make money off of it, second, there's a password on the skin package file which you haven't provided.1 point -
I saw this #2156 about adding IsDir & IsFile natively to AutoIt, but I did wonder why, since this could be easily achieved using functions already present in AutoIt and quite rightly so this ticket was rejected. Here are the functions. ConsoleWrite("IsDir: Using a file - " & IsDir(@ScriptFullPath) & @CRLF) ; Return 0 ConsoleWrite("IsFile: Using a file - " & IsFile(@ScriptFullPath) & @CRLF) ; Return 1 ConsoleWrite("IsDir: Using a directory - " & IsDir(@ScriptDir) & @CRLF) ; Return 1 ConsoleWrite("IsFile: Using a directory - " & IsFile(@ScriptDir) & @CRLF) ; Return 0 Func IsDir($sFilePath) Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) > 0) EndFunc ;==>IsDir Func IsFile($sFilePath) Return Number(FileExists($sFilePath) And StringInStr(FileGetAttrib($sFilePath), "D", 2, 1) = 0) EndFunc ;==>IsFile1 point