Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/29/2023 in all areas

  1. We use hash tables quite often in AutoIt. Be it the Scripting.Dictionary object or now the built-in AutoIt maps. But using something is still a difference to understanding how these data structures work internally. To make this more understandable for me I thought: What could be more obvious than implementing my own hash table in AutoIt? The result is this UDF. So if you want to understand for yourself how hash tables work exactly, you can have a close look at them in familiar AutoIt code. For productive purposes the UDF is of course rather not intended, because the alternatives Scripting.Dictionary and AutoIt-Maps offer more. Only from a very large number of elements (~ 1,000,000 elements) this UDF could be faster than the AutoIt maps. How to use the hash table?: example #1: #include "hashtable.au3" #include "Array.au3" Global $aTable = _hashtable_Create() _hashtable_Add($aTable, "banana", "the value of banana") _hashtable_Add($aTable, "apple", "the value of apple") _hashtable_Add($aTable, "apricot", "the value of apricot") _hashtable_Add($aTable, "orange", "the value of orange") ; remove element: _hashtable_Remove($aTable, "apple") ; get value with key: $value = _hashtable_Get($aTable, "apricot") MsgBox(0, "value for: apricot", $value) ; get the Keys as an array $aKeys = _hashtable_getKeys($aTable) _ArrayDisplay($aKeys, "The keys of the hash-table", "", 64) ; get the values as an array $aValues = _hashtable_getValues($aTable) _ArrayDisplay($aValues, "The values of the hash-table", "", 64) example #2: #include "hashtable.au3" #include "Array.au3" Global $aTable = _hashtable_Create() For $i = 1 To 10000 _hashtable_Add($aTable, "element " & Random(1, 1000, 1), "test-string " & $i) Next ; get the Keys as an array $aKeys = _hashtable_getKeys($aTable) ; get the values as an array $aValues = _hashtable_getValues($aTable) ; get all key-value pairs $aKeyValues = _hashtable_getKeyValues($aTable) _ArrayDisplay($aKeyValues) hashtable.au3
    3 points
  2. mko

    JSON UDF in pure AutoIt

    Just a very, very little thing... I think description of this funktion is wrong -copy Past error ; #FUNCTION# ====================================================================================== ; Name ..........: _JSON_Generate ; Description ...: convert a JSON-formatted string into a nested structure of AutoIt-datatypes Must be like in the funktion list description... - converts a nested AutoIt data structure into a JSON structured string.
    2 points
  3. Uploaded an updated ZIP file with these changes: Restored/incorporated the proper.case functionality again into the new autocomplete functions.It will now "proper.case" any known Function/UDF/Keyword/Macro/Directive. Macro's will now also be shown in the AutoComplete dropdown box Jos
    2 points
  4. pixelsearch

    RegExpQuickTester 2.5r

    Hi everybody Here is the script I use to test RegEx patterns offline, it's handy. Credits go to Lazycat, who scripted it initially many years ago and thanked "w0uter for ideas and parts of code". I added some modifications (listed in next post) and would like to thank @jchd @mLipok @mikell @Nine @mistersquirrle @taurus905 and @ioa747 for their contribution. Below are the match text & patterns corresponding to the pic above. For a start, you can copy and paste them in their respective edit control. After you choose the corresponding RegExp mode from the ComboBox at the bottom of the screen (mode 3 = return array of global matches) then you'll have the same results as displayed in the pic above. Match Text : blabla...blabla... blabla..."https://media.pic1.jpg"blabla..."https://media.pic2.png"... blabla..."https://media.pic3.jpg"blabla..."https://media.pic4.png"... blabla...blabla... Pattern : (?i)"([^"]+?\.(?:jpg|png))" When you end the script, 2 files will be created in the same directory of the script. Assuming your script is named "RegExpQuickTester 2.5p.au3", the 2 files created will be : * "RegExpQuickTester 2.5p.txt" which contains the saved Match Text that will be reused when you run the script. * "RegExpQuickTester 2.5p.ini" which contains the saved options that will be reused when you run the script. A right click while hovering over the Edit control of the Search Pattern will display a helpful context menu, with possibility to paste something from the menu inside the Search Pattern. Personally I nearly don't paste anything from the context menu but as this feature was created by the original scripter... Instead I like to consult this context menu as a RegExp syntax reminder ! Anyway, just experiment it and choose what's best for you. 99% of the time, the Search Pattern Tab will be on top. If you notice another colored Tab (except the Personal Tab which will never be highlited), then it means that there is something written in this other tab : the color is here only to remind you that there IS something in this other tab, in case you had forgotten. Even a space or a blank line would color the Tab. YJ This particular design (due to original scripter) won't allow you to type "" in the Replace Pattern Tab (mikell frowned, concerning this missing feature). Gladly I found that typing a non existing group, for example $99 will have the same effect as "" so it's a workaround that seems to do the job. The "Code" button allows you to generate the corresponding AutoIt code, which will be copied to the Clipboard Don't hesitate to ask if you have questions. Our RegExp gurus (that's not me) just love RegExp questions Edit: I forgot. You can drag a text file (or htm etc...) inside the Match Text edit control (it's a droppable zone) . There shouldn't be a 32Kb file size limit anymore as I added code to override this limit. There are probably a couple of other functionalities I'm not thinking of now, you'll easily find what you need if you look at the code. And if you want to modify something in the code, don't hesitate. Just share here your modifications in case other users find them useful too, thanks. Updates are detailed in next post Download last version 11 nov 2024 : RegExpQuickTester 2.5r.au3
    1 point
  5. Introduction JSON is a pure data exchange format. Basically you only have to deal with JSON in 2 places in a program: Once when reading JSON data and once when outputting data. In between it should not really matter that the data used to be JSON or should be converted to it. You should not need any special intermediate structures but only the elements that the respective programming language provides anyway. This is exactly the approach of this UDF: There is the function _JSON_Parse(), which converts an arbitrary JSON string into (nested) pure AutoIt data types (Arrays, Maps, Strings, Numbers, Null, True, False). And on the other side we have the function _JSON_Generate(), which generates a JSON string from arbitrary (nested) AutoIt data structures. Import and export JSON So how to use - let`s give an example: Handling nested data structures JSON is often very nested. The resulting AutoIt data is therefore naturally also nested, which makes it somewhat cumbersome to process with pure AutoIt on-board methods. For this reason, the UDF comes with a few helper functions that make life with this data easier. One of them is _JSON_Get(), which allows you to access deeply nested data with a simple query syntax. On the other hand there is the function _JSON_addChangeDelete() with which you can (the name already says it) change, add and delete data. You can even easily create deeply nested structures with a single call. Again, here is a small example of how to use it: Strictly speaking, these functions should not even have "JSON" in their names, since they are generally applied to data structures in AutoIt. However, since they are often used in the JSON environment, we allow ourselves this small inaccuracy. Why should i give it a try? Probably the most common method to deal with JSON in AutoIt is the variant via JSMN. My minor dissatisfactions with this approach led me to write this UDF in the first place a few years ago. So the incentives are quite JSMN related: Parsing and extraction of data is faster than in JSMN. (Only if the JSON string makes heavy use of JSON escapes should JSMN be a bit faster in parsing, since the escapes are resolved later.) Editing the data is easier, because you don't need special commands for the JSMN intermediate structure but deal directly with AutoIt structures. Generating JSON is also simple: build your structure in AutoIt as you like and then let it generate a JSON string for you with _JSON_Generate(). The UDF is smaller (28kb vs. 45kb) The UDF is in pure AutoIt. You can directly customize any behavior as you like. >>sourcecode and download on github<<
    1 point
  6. local $a=pack(948) local $b=map(sumSelfAndSquare,$a) msgbox(0,'',unpack($a)) msgbox(0,'',unpack($b)) func map($f,$xs) return IsArray($xs[0]) ? __mapContinue($f,$xs) : __mapLast($f,$xs) endfunc func __mapContinue($f,$xs) local $arr = [ map($f,$xs[0]) , $f($xs[1]) ] return $arr endfunc func __mapLast($f,$xs) local $arr = [$f($xs[0])] return $arr endfunc func unpack($arr) return IsArray($arr[0]) ? $arr[1] & ' , ' & unpack($arr[0]) : $arr[0] endfunc func pack($n) if $n<1 then local $a = [ $n ] else local $a = [ pack($n-1) , $n ] endif return $a endfunc func sumSelfAndSquare($x) return $x*$x + $x endfunc
    1 point
  7. To be honest, DllOpen is as useless as DllClose. Do you own testing, with and without DllOpen. You are saving nanoseconds only on each call. It will not make your slow program suddenly fast.
    1 point
  8. I think I can adapt the section in SciTEConfig.au3, which is ran at the end of the install process to finalize some things. I added some extra code which scans through the parent processes and when a different name is found, it will copy the %LOCALAPPDATA% from the Installer UserName to the Parent UserName directory and also update the "HKEY_USERS\SID\Environment" key "SCITE_USERHOME". So all should be good after the Environment load is forced (Kill Explorer or LogOff/LogOn) Still need to do some testing with the actual installer but running the script itself elevated with an different admin account seems to work fine.
    1 point
  9. I noticed this myself a while ago and have already adjusted it in my local master version. But for an extra upload it was then still too low for me. But sure - I have uploaded the silent update even. By the way, the parameter description in the function was also garbage. Such errors are typical for me, since I am not a native english speaker and therefore such things do not jump directly into my eye.
    1 point
  10. Ok... I have tested a bit in VM and see indeed in the install.log that the Admin user is used as target for the %localappdata% files and Registry settings. Next question to answer: How can I get the original UserId in this situation so I can use that in the NSIS script.... needs some investigation.
    1 point
  11. My use case is that only I am working on the computer with SciTE4AutoIt3, but the installation has to be done with an admin account as described before.
    1 point
  12. In fact, there was no direct reference. Primarily, the UDF is actually built from scratch with the help of some educational presentations just to achieve the learning effect. Only the hash function (djb2) I got by research for a suitable function. The real reason for this UDF are my performance tests for the new datatype Map in AutoIt. I wanted to understand the obtained results and why they behave in such a way especially with large element sets. For this I had to understand more what was going on under the hood. No, please don't. Leave it in. It's not about a concrete implementation or a productive use, but to make others understand what happens internally in a hash table. It makes sense to compare several implementations. What I like in your code is that the hash function depends on the data type. In my case, one is simply used for everything (which I thought made sense, since only integers or strings should be used as keys anyway).
    1 point
  13. @noellarkin Have you ever tested your function?: Local $aTmp[0] ConsoleWrite("0:" & @TAB & @TAB & _ValueIsNull(0) & @CRLF) ConsoleWrite("NULL:" & @TAB & _ValueIsNull(NULL) & @CRLF) ConsoleWrite('"":' & @TAB & @TAB & _ValueIsNull("") & @CRLF) ConsoleWrite('-1:' & @TAB & @TAB & _ValueIsNull(-1) & @CRLF) ConsoleWrite('False:' & @TAB & _ValueIsNull(-1) & @CRLF) ConsoleWrite('[]:' & @TAB & @TAB & _ValueIsNull($aTmp) & @CRLF) Func _ValueIsNull($value) $value = String($value) If IsString($value) And $value = "0" Or $value = "" Or $value = "-1" Or $value = "False" Or $value = "_FFCmd_Err" And $value = "[]" Then Return 1 EndFunc If you want to check explicitly for NULL, then use IsKeyWord(): $x = Null ; "", 0 If IsKeyword($x) = 2 Then MsgBox(0, "", "$x IS NULL") Else MsgBox(0, "", "$x IS NOT NULL") EndIf
    1 point
  14. mLipok

    au3 from editor?

    You really should find out the real source of the issue and fix them. Give use more details about the issue.
    1 point
  15. A light in the darkness as always, Melba. None of the previous discussions I read on this topic presented this (better) solution. I think it's about time you consider uploading your AutoIt knowledge to an AI for posterity's sake (maybe with a Yoda-voiced speech synthesizer?). Who wouldn't want a pocket-sized Melba sitting on their shoulder, whispering snazzy GUI solutions in one's ear? It would have saved me from writing this Rube-Goldberg contraption. I guess you'd need a dummy control if all menu items are to function as buttons : #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $mDummy = GUICtrlCreateMenu("") $mSpecialitem = GUICtrlCreateMenuItem("&Special", -1) $mSpecialitem2 = GUICtrlCreateMenuItem("&Special2", -1) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $mSpecialitem MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!") Case $mSpecialitem2 MsgBox($MB_SYSTEMMODAL, "Hello", "I can ALSO be actioned!") EndSwitch WEnd
    1 point
  16. I think this is pretty cool, took me a while to get my head around it, and I assume that you meant to post it in the example scripts section, unless you have a question? I also changed the names of some params to better understand it personally, and while it's neat, I don't see a use for it myself. Here's my updates, and comparison to a 'normal' way of doing it in AutoIt: Global $hTimer = TimerInit() #Region Haskell-like Global $a = pack(948) ConsoleWrite('pack(948): ' & Round(TimerDiff($hTimer), 2) & ' ms' & @CRLF) $hTimer = TimerInit() Global $b = map(sumSelfAndSquare, $a) ConsoleWrite('map(sumSelfAndSquare, $a): ' & Round(TimerDiff($hTimer), 2) & ' ms' & @CRLF) $hTimer = TimerInit() ConsoleWrite('unpack($a): ' & unpack($a) & ': ' & Round(TimerDiff($hTimer), 2) & ' ms' & @CRLF & @CRLF) $hTimer = TimerInit() ConsoleWrite('unpack($b): ' & unpack($b) & ': ' & Round(TimerDiff($hTimer), 2) & ' ms' & @CRLF & @CRLF) #EndRegion Haskell-like #Region Normal array and loop $hTimer = TimerInit() Global $aPack[948] ConsoleWrite('$aPack[948]: ' & Round(TimerDiff($hTimer), 2) & ' ms' & @CRLF) $hTimer = TimerInit() For $iIndex = 0 To UBound($aPack) - 1 $aPack[$iIndex] = sumSelfAndSquare($iIndex) Next ConsoleWrite('$aPack = sumSelfAndSquare: ' & Round(TimerDiff($hTimer), 2) & ' ms' & @CRLF) $hTimer = TimerInit() For $iIndex = 0 To UBound($aPack) - 1 ConsoleWrite($aPack[$iIndex] & (($iIndex = UBound($aPack) - 1) ? '' : ' , ')) Next ConsoleWrite(@CRLF) ConsoleWrite('$aPack logging: ' & Round(TimerDiff($hTimer), 2) & ' ms' & @CRLF) #EndRegion Normal array and loop Func map($sFunc, $aPackedData) Return IsArray($aPackedData[0]) ? __mapContinue($sFunc, $aPackedData) : __mapLast($sFunc, $aPackedData) EndFunc ;==>map Func __mapContinue($sFunc, $aPackedData) Local $aArray = [map($sFunc, $aPackedData[0]), $sFunc($aPackedData[1])] Return $aArray EndFunc ;==>__mapContinue Func __mapLast($sFunc, $aPackedData) Local $aArray = [$sFunc($aPackedData[0])] Return $aArray EndFunc ;==>__mapLast Func unpack($aArray) Return IsArray($aArray[0]) ? $aArray[1] & ' , ' & unpack($aArray[0]) : $aArray[0] EndFunc ;==>unpack Func pack($iIndex) If $iIndex > 0 Then Local $a = [pack($iIndex - 1), $iIndex] ElseIf $iIndex = 0 Then Local $a = [$iIndex] Else Local $a = [1] Return SetError(1, $iIndex, $a) EndIf Return $a EndFunc ;==>pack Func sumSelfAndSquare($x) Return $x * $x + $x EndFunc ;==>sumSelfAndSquare For me it took around ~30ms for the Haskell like code (excluding unpacking $a), and ~6.7ms for the normal array approach. I can't personally see any use for implementing this, considering that it took me a while to understand what's happening, it just wouldn't be worth it to me to add this complexity for no benefit that I can see. Please let me know if I'm missing some awesome use-case for this. Otherwise again I do think this is neat. And kudos to you for implementing it with AutoIt.
    1 point
  17. Another suggestion if I may. To allow use this UDF in multiple applications on the same machine, perhaps the server name could be supplied as an argument to the _WCD_CreateServer(). This will also allow create a more secure link between two instances of the same script (i.e. using Multi-task udf) by generating random server name, or run two servers for a true 2-way communication.
    1 point
  18. RTFC, If you use the native menu functions it is a little bit easier: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $mFilemenu = GUICtrlCreateMenu("&File") $mExititem = GUICtrlCreateMenuItem("E&xit", $mFilemenu) $mSpecialitem = GUICtrlCreateMenuItem("&Special", -1) $mHelpmenu = GUICtrlCreateMenu("?") $mAboutitem = GUICtrlCreateMenuItem("&About", $mHelpmenu) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $mExititem Exit Case $mSpecialitem MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!") Case $mAboutitem MsgBox($MB_SYSTEMMODAL, "Solved", "Thank Jos for that!") EndSwitch WEnd M23
    1 point
  19. I understand your arguments and they are quite valid. I wanted to offer an easy way to exit the server, and a check if there are still messages waiting in queue. But this can be made optional if need be. Meanwhile, If you want to clean up your server script, you can use OnAutoItExitRegister (as you probably know)
    1 point
  20. Looking for a solution for this: I am using _WD_Window($sSession, 'rect', '{ "x":####, "y":####, "height":####, "width":#### }') function to position 2 browser windows on different desktop monitors. The monitors have different screen resolutions. This means the symbology/text sizing is wrong on one of the monitors when I size/position the browsers. Anyone know if there is a way to account for this? I could change out a monitor, except one of the monitors is rotated vertically.
    1 point
  21. Wow, 2 years... So I figured out a way to do this recently, using AutoIt actually. I put this in my SciTEUser.properties file: command.42.*="$(autoit3dir)\autoit3.exe" /AutoIt3ExecuteLine "WinMenuSelectItem('[CLASS:SciTEWindow]', '', '&File', '&1')" command.name.42.*=Open Most Recent File command.shortcut.42.*=Ctrl+Shift+T command.save.before.42.*=2 I'm only replying because I actually forgot that I'd asked this question before, and when I was trying to figure it out recently, a Google search led me back to this thread. So just in case someone else ever finds this thread via Google, now there's a solution!
    1 point
  22. rootx, You will have to do some pre/post-processing of the section names if you think there might be [ ] characters in the section name: #include <Array.au3> $sIniFile = "Test.ini" $sPath = "C: \ name [IBIS 001] 2017\file.txt" $sEscPath = StringReplace(StringReplace($sPath, "[", "\5B"), "]", "\5D") IniWrite($sIniFile, $sEscPath, "Key", "Value") $aSections = IniReadSectionNames($sIniFile) For $i = 1 To $aSections[0] $aSections[$i] = StringReplace(StringReplace($aSections[$i], "\5B", "["), "\5D", "]") Next _ArrayDisplay($aSections, "", Default, 8) And please do not be so quick to declare a bug - best ask first next time. M23
    1 point
×
×
  • Create New...