Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/30/2020 in all areas

  1. My two three cents: (whatever they're worth ) 1. Arrays resizing (ReDim) is a costly process. To speed things up, don't do it every time you find a match. Instead, either calculate the largest number of possible results up front and then size your array, or start with an array of say 100 and add as needed. At the very least, right now you're resizing your array after every match and at the end. Instead, just resize it when you get a match (start with $iIndex = 0 and resize before adding the value to the array). 2. I'm not sure (because I haven't tested), but I would think that calling _ArrayFindAll once instead of _ArraySearch many times would be more efficient. 3. I think that an invalid string passed in $iRanges (shouldn't that be $sRanges?) will break your function... you aren't checking the @error value of StringSplit. And yeah, GIGO, but I try to handle all the garbage I can find That said, as long as it works for you, who cares?! I probably would've started with the results from _ArrayFindAll and chucked out all the results I didn't need, but that's probably wasteful. It's a good function if you have a need for it!
    2 points
  2. I don't know how big your picture is, but you made a list with only 16x16 pixels. Here a working example: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Fileversion=0.0.0.12 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GuiComboBoxEx.au3> #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GDIPlus.au3> Global $g_idMemo Example() Func Example() Local $hGUI, $hImage, $hCombo ; Create GUI $hGUI = GUICreate("ComboBoxEx Set Image List", 1000, 800) $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 994, 500) $g_idMemo = GUICtrlCreateEdit("", 2, 332, 396, 266, 0) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) _GDIPlus_Startup() InetGet("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/World_blank_map_countries.PNG/320px-World_blank_map_countries.PNG", "World.png") $hImage = _GUIImageList_Create(320, 140, 5, 3, 1) SetComboImage($hImage, @ScriptDir & "\World.png") SetComboImage($hImage, @ScriptDir & "\World.png") ;Set Image List Local $hPrevlist = _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) MemoWrite("Previous ImageList Handle: " & $hPrevlist & _ " IsPtr = " & IsPtr($hPrevlist) & " IsHWnd = " & IsHWnd($hPrevlist)) For $x = 0 To 1 _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : Picture", $x + 1), $x, $x) Next ;Get Image List MemoWrite("ImageList Handle: " & _GUICtrlComboBoxEx_GetImageList($hCombo)) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Func SetComboImage($hImage, $iFilename) Local $hPng = _GDIPlus_ImageLoadFromFile($iFilename) ;~ ConsoleWrite($hPng & @CRLF) Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPng) ;~ ConsoleWrite($hBmp & @CRLF) ConsoleWrite(_GUIImageList_Add($hImage, $hBmp) & @CRLF) EndFunc
    2 points
  3. The listview refresh works if you solve this problem in your variables : ; $LV_Files is the control ID of the listview : correct $LV_Files = GUICtrlCreateListView(...) ; $LV_Files is now the "Index number of ListView for use in other GUIListViewEx functions" : incorrect $LV_Files = _GUIListViewEx_Init($LV_Files, "", 0, 0xFF0000, True, 1 + 4 + 8) You cannot use the same variable for both because the ListView id is wrong now (it was = 3, now = 1) . To solve this, just create another variable, named for example $LV_FilesEx, changing 5 lines in the script : $LV_FilesEx = _GUIListViewEx_Init($LV_Files, "", 0, 0xFF0000, True, 1 + 4 + 8) ; change THREE times ... Local $sSelected = _GUIListViewEx_GetLastSelItem($LV_FilesEx) ; col|row|cel ... $answ = _GUIListViewEx_Close($LV_FilesEx) Then you'll have a correct refresh after any click on "delete file" or "add file"
    1 point
  4. I'm doing a small update over the V2.92 based on the @itagashu comments. I couldn't use COM10 under Windows 10 64bits. ComUDF V2.93: - COM port numbers above 9; - Keeping two examples. ComUDF_V293.zip
    1 point
  5. You have @sw_hide where the working directory should be. Try: Run(@ComSpec & " /c " & $NETCMD, "", @SW_HIDE, $STDOUT_CHILD) If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "An error occurred executing command - @error = " & @error) You should also add error checking. If you had checked @error, you would have seen that you had a problem with the statement.
    1 point
  6. Due to several reasons, AU3Text was just not working out for me... so instead, I decided to create my own version: It uses a forked version of EasyCodeIt to extract the translation strings and internally uses Scripting.Dictionary to keep track of the strings.
    1 point
  7. abberration

    AutoIt Snippets

    Hi, seadoggie01, You make a great point about ReDim. I will look at the code soon and try to rework it to only ReDim once. _ArrayFindAll is what I used to model my function. It uses _ArraySearch for it's results, so using _ArrayFindAll should not be any faster. You are correct, I should have done more error checking. Before I put in the one @error, when I passed bad info, it only returned an empty array. When I put in the one @error, it seemed to return the correct error handle. But I do need to do more testing in this area. I got it working and was very tired, so I just posted it. I will continue working on it. I think it could be a very useful addition when it's perfected. I have already determined that declaring the default value of $iRanges is useless as it is. I need to work on that. Thank you for your suggestions. I will use them to improve the script.
    1 point
  8. Not sure if this has been corrected or not but I downloaded the most recent version (2.1.16 BETA), there is a bug in __ADO_MSSQL_CONNECTION_STRING_WinAuth and caused me a huge headache as I was getting provider not found errors when I knew the provider was installed fine. The curly brackets are not needed around the PROVIDER= $sConnectionString = "PROVIDER={" & _ADO_MSSQL_GetProviderVersion() & "};SERVER=" & $sServer & ";DATABASE=" & $sDataBase & ";" should be $sConnectionString = "PROVIDER=" & _ADO_MSSQL_GetProviderVersion() & ";SERVER=" & $sServer & ";DATABASE=" & $sDataBase & ";" I also added Integrated Security=SSPI; to this line... $sConnectionString &= "Trusted_Connection=True;Integrated Security=SSPI;"
    1 point
  9. funkey

    autoit send ctrl+q

    Send("^q")
    1 point
  10. Have a look at the helpfile for StdoutRead the example shows how to read the cmd window output.
    1 point
  11. ; Here's a quick example use: ; run a full list from a CMD box ; we should have more or less the same content without disclosing personal details ; can also be done with AutoIt functions, recursively enumerating subfolders and files ; C:\Program Files (x86)\AutoIt3>dir /b /a:-d /s > C:\Users\jc\Documents\AutoMAT\tmp\au3files.txt #include <File.au3> #include <SQLite.au3> Const $SQLITE_DLL = "C:\SQLite\bin\sqlite3.dll" ;<-- Change to the location of your sqlite dll ; Init sqlite _SQLite_Startup($SQLITE_DLL, False, 1) If @error Then Exit MsgBox($MB_ICONERROR, "SQLite Error", "Unable to start SQLite. Check existence of DLL") OnAutoItExitRegister(_SQLite_Shutdown) ConsoleWrite("SQlite version " & _SQLite_LibVersion() & @LF & @LF) ; optional! Local $hDB = _SQLite_Open("AllFiles.sq3") If @error Then Exit OnAutoItExitRegister(SQ3Close) ; as requested, drive isn't stored _SQLite_Exec($hDB, "CREATE TABLE if not exists Dirs (" & _ "ID INTEGER PRIMARY KEY, " & _ "Dir CHAR NOT NULL UNIQUE)") _SQLite_Exec($hDB, "CREATE TABLE if not exists Files (" & _ "ID INTEGER PRIMARY KEY, " & _ "DirId INTEGER NOT NULL CONSTRAINT fkFileDir REFERENCES Dirs (ID) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, " & _ "File CHAR NOT NULL, " & _ "Ext CHAR NOT NULL DEFAULT '')") _SQLite_Exec($hDB, "CREATE INDEX if not exists ixFileExt ON Files (File, Ext);") _SQLite_Exec($hDB, "CREATE INDEX if not exists ixExt ON Files (Ext);") ; can also be done with AutoIt functions, recursively enumerating subfolders and files Local $aFiles = FileReadToArray("C:\Users\jc\Documents\AutoMAT\tmp\au3files.txt") Local $aRow, $iId, $sDrive, $sDir, $sFile, $sExt ; Make the whole insert block into a transaction to speed up things. _SQLite_Exec($hDB, "begin") For $v In $aFiles _PathSplit($v, $sDrive, $sDir, $sFile, $sExt) _SQLite_QuerySingleRow($hDB, "select id from dirs where dir = " & _SQLite_FastEscape($sDir), $aRow) If @error Then _SQLite_Exec($hDB, "insert into dirs (dir) values (" & _SQLite_FastEscape($sDir) & ")") $iId = _SQLite_LastInsertRowID($hDB) Else $iId = $aRow[0] EndIf If $sFile = '' Then ContinueLoop _SQLite_Exec($hDB, "insert into files (dirid, file, ext) values (" & $iId & ", " & _SQLite_FastEscape($sFile) & ", " & _SQLite_FastEscape($sExt) & ")") Next ; commit _SQLite_Exec($hDB, "end") Func SQ3Close() _SQLite_Close($hDB) EndFunc ; preferably use Expert to query the DB. Copy this query into a SQL tab and execute it ; select dir || file || ext "File" from dirs D join files F on d.id = f.dirid where dir not like '%beta%' and file like '%extended%' and ext = '.au3' This is a basic schema. SQL Foreign key reference work the opposite of pointers in conventional programming! An entry in the Dirs table holds a DirId (the unique identifier of the directory where the file resides). This is pretty standard SQL and how most tables in large DBs relate to each other. Put it otherwise, you don't store ID of every children to every parent, you store the ID of mother and father in each child entry. Run the sample code (adjust paths if necessary) and use Expert to see what's stored where. Then use an SQL tab to launch the sample query in final comment of the code to see what you get. You may want to create an extra table Params containing for instance: the drive for that DB, a schema version in case you need to upgrade to a new schema, the timestamp of last data retrieval or update, whatever information you find useful. Don't store counts, use SQL to retrieve counts by using AutoIt or (simpler) another Expert SQL tab (I get 47 but I've some more than bare minimum): _SQLite_QuerySingleRow($hDB, "select count(*) from files where ext = '.exe', $aRow) count is then in $aRow[0] A golden rule in SQL schema design: don't duplicate information, never, no, no. Create as many tables as required, and make relationships explicit (using foreign keys). Dirs table should contain information pertinent to directory entries, Files should contain information for files and hold a FK to the Dir where it lives.
    1 point
  12. Hello @GregEisenberg You need to do this: Local $oJsonRect=_WD_ElementAction($sSession, $sElements, 'rect') ConsoleWrite("!" & Json_Get($oJsonRect, "[x]") & @CRLF) ConsoleWrite("!" & Json_Get($oJsonRect, "[y]") & @CRLF) ConsoleWrite("!" & Json_Get($oJsonRect, "[width]") & @CRLF) ConsoleWrite("!" & Json_Get($oJsonRect, "[height]") & @CRLF) Saludos
    1 point
  13. Return value from _WD_ElementAction I am trying to use the WebDriver to find the rectangle of an element on a page. The following is a function I wrote to do this, and in its current form it includes a bunch of debugging ConsoleWrite's also. The main issue is the return value from _WD_ElementAction. I have read _WD_ElementAction source code and I would expect it to return a string a Json BUT when I use it i get nothing as a return. Initially I expected the response to be Which is what i see in the debug output. But on closer look to the source code it seems that _WD_ElementAction may parse out the "value" and only return But in my code I get nothing as a return value. Below is my code. Can anyone help? Should I expect a response from _WD_ElementAction? Should I expect it to be JSon? Func FindElementRect($session, $elementToFind) $feResult = _WD_FindElement($session, $_WD_LOCATOR_ByID, $elementToFind) ConsoleWrite("_WD_FindElement result: " & $feResult & @CRLF) ConsoleWrite("**** : " & _WD_ElementAction($session, $feResult, "rect")) ; i can see something returned here $eaResult = _WD_ElementAction($session, $feResult, "rect") ; in this case eaResult is blank ConsoleWrite("$eaResult: " & $eaResult & @CRLF) ConsoleWrite("@error is: " & @error & @CRLF) ; never an error ; per debug log this is what I expect to get ;{"value":{"height":21,"width":79,"x":8,"y":62}} $oJson = Json_Decode($eaResult) Local $rect[4] $rect[0] = Json_Get($oJson, "[value][x]") ConsoleWrite("top Left X: " & $rect[0] & @CRLF) $rect[1] = Json_Get($oJson, "[value][y]") ConsoleWrite("top Left Y: " & $rect[1] & @CRLF) $rect[2] = $rect[0] + Json_Get($oJson, "[value][width]") ConsoleWrite("bottom right X: " & $rect[2] & @CRLF) $rect[3] = $rect[1] + Json_Get($oJson, "[value][height]") ConsoleWrite("bottom right Y: " & $rect[3] & @CRLF) return $rect EndFunc Many thanks in advance Greg
    1 point
  14. A .csv file must adhere to the RFC standard or desist from calling itself .csv
    1 point
×
×
  • Create New...