Leaderboard
Popular Content
Showing content with the highest reputation on 12/30/2020 in all areas
-
Multiple Character Replacement
Musashi and one other reacted to pixelsearch for a topic
Hi everybody It's interesting to have a look at the evolution of the code concerning _StringRepeat() , code found in the include file String.au3 . Before opening the au3 file, I thought that it would be as simple as this : Func _StringRepeat($sString, $iRepeatCount) Local $sResult = "" For $iCount = 1 To $iRepeatCount $sResult &= $sString Next Return $sResult EndFunc ;==>_StringRepeat That's (nearly) the code written by Jeremy Landes and found in AutoIt version 3.3.8.1 (29th January, 2012) A bit later, @guinness optimised this code in version 3.3.10.0 (23rd December, 2013) by scripting it like that (which is the actual version) : Func _StringRepeat($sString, $iRepeatCount) ... Local $sResult = "" While $iRepeatCount > 1 If BitAND($iRepeatCount, 1) Then $sResult &= $sString $sString &= $sString $iRepeatCount = BitShift($iRepeatCount, 1) WEnd Return $sString & $sResult EndFunc ;==>_StringRepeat Not only some ms were gained with this optimisation, but it's interesting to have a look at the Console with a couple of examples : _StringRepeat("+-", 16) 16 0 +-+- 8 8 0 +-+-+-+- 4 4 0 +-+-+-+-+-+-+-+- 2 2 0 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- 1 _StringRepeat("+-", 21) 21 1 +-+- 10 +- 10 0 +-+-+-+- 5 +- 5 1 +-+-+-+-+-+-+-+- 2 +-+-+-+-+- 2 0 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- 1 +-+-+-+-+- 1st column : $iRepeatCount, at the beginning of the loop 2nd column : BitAnd, returns 0 or 1 depending on $iRepeatCount being even or odd 3rd column : $sString, after its concatenation within the loop (doubling) 4th column : $iRepeatCount, after its Bitshift within the loop (halving) 5th column : $sResult, updated only when BitAnd() returned 1 There is no 5th column in example _StringRepeat("+-", 16) because all BitAnd's returned 0 That's an interesting way to study BitShift and BitAnd, especially focusing on this line : If BitAND($iRepeatCount, 1) Then $sResult &= $sString Thanks @guinness and a happy new year to all of you2 points -
Agree, but first needs to be properly tested to see if everything keeps working and I haven't done that yet. So ... input/feedback is welcome before doing so! My preference is to do this without adding an option and just default to these changes when they work also for regular text/names. Jos2 points
-
https://www.libreoffice.org/download/download/ https://download.documentfoundation.org/libreoffice/stable/7.0.4/win/x86_64/LibreOffice_7.0.4_Win_x64_sdk.msi "c:\Program Files\LibreOffice_7.0_SDK\sdk\examples\OLE\vbscript\WriterDemo.vbs" '*********************************************************************** '* '* The Contents of this file are made available subject to the terms of '* the BSD license. '* '* Copyright 2000, 2010 Oracle and/or its affiliates. '* All rights reserved. '* '* Redistribution and use in source and binary forms, with or without '* modification, are permitted provided that the following conditions '* are met: '* 1. Redistributions of source code must retain the above copyright '* notice, this list of conditions and the following disclaimer. '* 2. Redistributions in binary form must reproduce the above copyright '* notice, this list of conditions and the following disclaimer in the '* documentation and/or other materials provided with the distribution. '* 3. Neither the name of Sun Microsystems, Inc. nor the names of its '* contributors may be used to endorse or promote products derived '* from this software without specific prior written permission. '* '* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS '* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE '* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, '* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, '* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS '* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND '* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR '* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE '* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '* '************************************************************************* 'The service manager is always the starting point 'If there is no office running then an office is started up Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager") 'Create the CoreReflection service that is later used to create structs Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection") 'Create the Desktop Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop") 'Open a new empty writer document Dim args() Set objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args) 'Create a text object Set objText= objDocument.getText 'Create a cursor object Set objCursor= objText.createTextCursor 'Inserting some Text objText.insertString objCursor, "The first line in the newly created text document." & vbLf, false 'Inserting a second line objText.insertString objCursor, "Now we're in the second line", false 'Create instance of a text table with 4 columns and 4 rows Set objTable= objDocument.createInstance( "com.sun.star.text.TextTable") objTable.initialize 4, 4 'Insert the table objText.insertTextContent objCursor, objTable, false 'Get first row Set objRows= objTable.getRows Set objRow= objRows.getByIndex( 0) 'Set the table background color objTable.setPropertyValue "BackTransparent", false objTable.setPropertyValue "BackColor", 13421823 'Set a different background color for the first row objRow.setPropertyValue "BackTransparent", false objRow.setPropertyValue "BackColor", 6710932 'Fill the first table row insertIntoCell "A1","FirstColumn", objTable insertIntoCell "B1","SecondColumn", objTable insertIntoCell "C1","ThirdColumn", objTable insertIntoCell "D1","SUM", objTable objTable.getCellByName("A2").setValue 22.5 objTable.getCellByName("B2").setValue 5615.3 objTable.getCellByName("C2").setValue -2315.7 objTable.getCellByName("D2").setFormula"sum <A2:C2>" objTable.getCellByName("A3").setValue 21.5 objTable.getCellByName("B3").setValue 615.3 objTable.getCellByName("C3").setValue -315.7 objTable.getCellByName("D3").setFormula "sum <A3:C3>" objTable.getCellByName("A4").setValue 121.5 objTable.getCellByName("B4").setValue -615.3 objTable.getCellByName("C4").setValue 415.7 objTable.getCellByName("D4").setFormula "sum <A4:C4>" 'Change the CharColor and add a Shadow objCursor.setPropertyValue "CharColor", 255 objCursor.setPropertyValue "CharShadowed", true 'Create a paragraph break 'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant objText.insertControlCharacter objCursor, 0 , false 'Inserting colored Text. objText.insertString objCursor, " This is a colored Text - blue with shadow" & vbLf, false 'Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK). objText.insertControlCharacter objCursor, 0, false 'Create a TextFrame. Set objTextFrame= objDocument.createInstance("com.sun.star.text.TextFrame") 'Create a Size struct. Set objSize= createStruct("com.sun.star.awt.Size") objSize.Width= 15000 objSize.Height= 400 objTextFrame.setSize( objSize) ' TextContentAnchorType.AS_CHARACTER = 1 objTextFrame.setPropertyValue "AnchorType", 1 'insert the frame objText.insertTextContent objCursor, objTextFrame, false 'Get the text object of the frame Set objFrameText= objTextFrame.getText 'Create a cursor object Set objFrameTextCursor= objFrameText.createTextCursor 'Inserting some Text objFrameText.insertString objFrameTextCursor, "The first line in the newly created text frame.", _ false objFrameText.insertString objFrameTextCursor, _ vbLf & "With this second line the height of the frame raises.", false 'Create a paragraph break 'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant objFrameText.insertControlCharacter objCursor, 0 , false 'Change the CharColor and add a Shadow objCursor.setPropertyValue "CharColor", 65536 objCursor.setPropertyValue "CharShadowed", false 'Insert another string objText.insertString objCursor, " That's all for now !!", false On Error Resume Next If Err Then MsgBox "An error occurred" End If Sub insertIntoCell( strCellName, strText, objTable) Set objCellText= objTable.getCellByName( strCellName) Set objCellCursor= objCellText.createTextCursor objCellCursor.setPropertyValue "CharColor",16777215 objCellText.insertString objCellCursor, strText, false End Sub Function createStruct( strTypeName) Set classSize= objCoreReflection.forName( strTypeName) Dim aStruct classSize.createObject aStruct Set createStruct= aStruct End Function2 points
-
As the WebDriver UDF - Help & Support thread has grown too big, I started a new one. The prior thread can be found here.1 point
-
Here an example : #include <Constants.au3> #include <WinAPISysWin.au3> #include <Misc.au3> $sURL = "www.google.com" ToolTip($sURL, Default, Default, "Click on me") Local $bClick = _ClickToolTip(5) MsgBox ($MB_SYSTEMMODAL,"Is tool tip clicked ?", $bClick) Func _ClickToolTip($iTimeOut) Local $hWnd = WinGetHandle("[CLASS:tooltips_class32]") If Not $hWnd Then Return False Local $hTimer = TimerInit() While TimerDiff($hTimer) < $iTimeOut*1000 Local $tRect = _WinAPI_GetWindowRect($hWnd) If _IsPressed("01") Then Local $aPos = MouseGetPos() If $aPos[0] >= $tRect.left And $aPos[0] <= $tRect.right And $aPos[1] >= $tRect.top And $aPos[1] <= $tRect.bottom Then ToolTip("") Return True EndIf EndIf WEnd ToolTip("") Return False EndFunc1 point
-
Clickable link in tooltip
caramen reacted to pixelsearch for a topic
Hi Caramen In this link, Nine helped me to retrieve the coords of a tooltip. Maybe it could help you to achieve your goal, for example by checking the mouse position during the $GUI_EVENT_PRIMARYDOWN event in the While... Wend loop of your main GUI ?1 point -
Just add the 2 lines to the original UDF: If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body $objEmail.HTMLBodyPart.CharSet = "UTF-8" Else $objEmail.Textbody = $as_Body & @CRLF $objEmail.TextBodyPart.CharSet = "UTF-8" EndIf Jos1 point
-
Calling all RegEx Masters...
JockoDundee reacted to mikell for a topic
In regex translated to common language this could mean "remove a char if it is preceded by 4 chars" StringRegExpReplace($txt, '(?<=\w{4})\w', "")1 point -
Calling all RegEx Masters...
JockoDundee reacted to AspirinJunkie for a topic
\b\w{4}\K\w No AutoIt Here but the pattern should work. Replace this with empty string.1 point -
1 point
-
I cant close an update message and reopen a software
lgkoliveira reacted to mikell for a topic
As you don't know whether this message will appear or not, you need to make the script wait for a while right after the first Run So you might put a Sleep() between this Run and the WinActive (1st script) , or use a timeout in the WinWaitActive (2nd script)1 point -
Non-focusable GUI does not give focus after calling "evil" functions
Professor_Bernd reacted to mikell for a topic
Yes , I already saw the example provided in the help for _WinAPI_GetGUIThreadInfo which is a nice alternative, but it doesn't work either for gui which use non-Windows components (like browsers or so)1 point -
Libre/openoffice Writer
Earthshine reacted to FrancescoDiMuro for a topic
@MarcoMonte Did you try the first UDF? It seems to work with LibreOffice too Sorry, I misread your request. Seems that there's no LibreOffice Writer UDF, but you could use the LibreOffice SDK to make your own1 point -
No idea, this UDF is using the standard CDO COM object, so you could try searching for this whether it can be set. Jos I know it's late, but anyway here it is: $objEmail.Fields("urn:schemas:mailheader:x-mailer") = "My application Name or whatever else" and here is the way how to set "code page" (here Czech) : this is important when you have chars with diacritics (special non-english letters) in your email $objEmail.BodyPart.ContentTransferEncoding = "8bit" $objEmail.BodyPart.CharSet = "windows-1250"1 point
-
An example of the Add and Update methods of ADO Recordset object (with MS Access): Opt("MustDeclareVars", 1) ;Opt("TrayIconDebug", 1) OnAutoItExitRegister("OnAutoItExit") Global $sFilePath = @DesktopDir & "\test.mdb" ;Help: COM Error Handling ;_ErrADODB From spudw2k ;https://www.autoitscript.com/forum/topic/105875-adodb-example/ Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") Global $cn, $rst, $sSQL Global $CreateTestDataBase = True Global Const $iCursorType = 3 ;0 adOpenForwardOnly, 3 adOpenStatic Global Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" ;Global $sADOConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" ;Global $sADOConnectionString = 'Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $sFilePath & ';uid=;pwd=MyPassword;' If $CreateTestDataBase Then ;mLipok, https://www.autoitscript.com/forum/topic/180848-example-xls-mdb-from-scratch-with-adox/ ;https://forums.autodesk.com/t5/visual-basic-customization/ado-connection-create-file-excel/td-p/1675928 ;https://msdn.microsoft.com/en-us/library/ms675849(v=vs.85).aspx ;https://msdn.microsoft.com/en-us/library/ms680934(v=vs.85).aspx Global $oCatalog = ObjCreate('ADOX.Catalog') FileDelete(@DesktopDir & "\test.mdb") ; <<< I'm not using $sFilePath for security: in reusing parts of the code $cn = $oCatalog.Create($sADOConnectionString) ;https://docs.microsoft.com/es-es/office/client-developer/access/desktop-database-reference/create-table-statement-microsoft-access-sql ;https://www.w3schools.com/sql/sql_create_table.asp ;http://www.vbforums.com/showthread.php?529221-RESOLVED-create-table-as-select-in-MS-Access ;https://docs.microsoft.com/es-es/office/client-developer/access/desktop-database-reference/select-into-statement-microsoft-access-sql $sSQL = "CREATE TABLE EMPLOYEES" _ & " (ID int identity, LastName varchar(40), FirstName varchar(40), Title varchar(40)," _ & " CONSTRAINT MyTableConstraint_PrimaryKey PRIMARY KEY (ID)," _ & " CONSTRAINT MyTableConstraint_Unique UNIQUE (LastName, FirstName));" $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 ;Some notes: ;Create Table Using Another Table ;A copy of an existing table can also be created using CREATE TABLE. ;The new table gets the same column definitions. All columns or specific columns can be selected. ;CREATE TABLE new_table_name AS ;SELECT column1, column2,... ;FROM existing_table_name ;WHERE ....; ;The following SQL creates a new table called "TestTables" (which is a copy of the "Customers" table): ;CREATE TABLE TestTable AS ;SELECT customername, contactname ;FROM customers; ;$sSQL = "SELECT *" _ ; & " INTO NEWTABLE" _ ; & " FROM [" & $sFilePath2 & ";PWD=123].SOMETABLE" ;$cn.Execute($sSQL, Default, 1 + 0x80) ;~ For $i = 1 To 5 ;~ $sSQL = "INSERT INTO EMPLOYEES (LastName, FirstName, Title)" _ ;~ & " VALUES ('" & "LastName_" & $i & "', '" & "FirstName_" & $i & "', '" & "Title_" & $i & "')" ;~ $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 ;~ Next $rst.Open("EMPLOYEES", $cn, $iCursorType, $iLockType, 2) ;Source (table name), ActiveConnection, CursorType, LockType, Options (adCmdTable) $cn.BeginTrans For $i = 1 To 5 $rst.AddNew $rst("LastName").Value = "LastName_" & $i $rst.Fields("FirstName") = "FirstName_" & $i $rst(3).Value = "Title_" & $i Next $rst.Update MsgBox(0,"","Last Auto-increment value is: " & $rst(0).Value) $rst.Close $cn.CommitTrans Else $cn = ObjCreate("ADODB.Connection") ; Create a connection object $cn.Open($sADOConnectionString) ; Open the connection EndIf ;MsgBox(0, "", $cn.ConnectionString) $cn.CursorLocation = 2 ;2 adUseServer, 3 adUseClient $cn.CommandTimeout = 60 ;https://support.microsoft.com/en-us/help/194973/prb-ado-recordcount-may-return--1 ;When you request the RecordCount for a serverside recordset, a -1 may return. This occurs with ActiveX Data Objects (ADO) version 2.0 or later when the CursorType is adOpenForwardonly or adOpenDynamic. Testing with the OLEDB provider for JET and SQL Server produces varying results, depending on the provider. ;Cause: The number of records in a dynamic cursor may change. Forward only cursors do not return a RecordCount. ;Resolution: Use either adOpenKeyset or adOpenStatic as the CursorType for server side cursors ;or use a client side cursor. Client side cursors use only adOpenStatic for CursorTypes regardless of which CursorType you select. ;https://stackoverflow.com/questions/31941487/open-adodb-connection-to-excel-file-in-read-only-mode ;https://www.w3schools.com/asp/prop_rec_mode.asp ;$cn.Mode = 1 ;Read-only ;To update an existing record, create a Recorset with one record at a time. ;This requires that there is some kind of unique key when identifying the records. ;After opening the recordset, use the .Fields property to change the field in question ;and then the .Update method to make changes to the database. $sSQL = "SELECT LastName, FirstName, Title FROM EMPLOYEES WHERE ID = 1" $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ; Issue the SQL query If Not $rst.EOF = True Then $rst("LastName").Value = "Davolio" $rst.Fields("FirstName") = "Nancy" $rst.Fields(2) = "President" EndIf $rst.Update MsgBox(0, "UPDATED RECORD", $rst.RecordCount) $rst.Close $rst = 0 $cn.Close ;Close the connection $cn = 0 ;Release the connection object Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext, 5) Local $err = $errADODB.number If $err = 0 Then $err = -1 $rst = 0 $cn.Close $cn = 0 Exit EndFunc Func OnAutoItExit() $rst = 0 ; Release the recordset object If IsObj($cn) Then If $cn.State > 0 Then $cn.Close ;adStateOpen Close the connection $cn = 0 ; Release the connection object EndIf EndFunc1 point
-
Hello, you can find a good example of capturing the output of a commandline program in my Process UDF, Just download the repository and play with Example.au31 point
-
Displaying updated variables in the GUI
ponty reacted to Xenobiologist for a topic
Hi, try this: #include <GUIConstants.au3> $var = IniRead("C:\Temp\mega.ini", "Mega", "1", "NotFound") GUICreate("My GUI", 150, 100, 5, 5) $read_B = GUICtrlCreateButton("Read again", 10, 10, 100, 30) $var_L = GUICtrlCreateLabel ($var, 10, 50, 100, 20, $SS_SUNKEN) GUISetState () ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select case $msg = $GUI_EVENT_CLOSE ExitLoop case $msg = $read_B GUICtrlSetData($var_L, IniRead("C:\Temp\mega.ini", "Mega", "1", "NotFound")) EndSelect Wend So long, Mega1 point -
0 points