Jump to content

Search the Community

Showing results for tags 'associative array'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum FAQ
  • AutoIt

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 3 results

  1. If you don't like dealing with Scripting.dictionary you might want to try out this thing I whipped up yesterday evening and this morning. Basically just a simple wrapper around Scripting.dictionary to make the API a little bit less stupid. By "stupid" I mean "not like the awesome Python dict API". Created for the following reasons.. Wanted to get a basic understanding of AutoItObject. Wanted to get a basic understanding of the Micro unit test framework. As of 11/4/2014 AutoIt Stable has no native dict or associative array type. A >Map type is in the current AutoIt beta. It's laborious to use Scripting.dictionary all the time. The Python dict API is better than Scripting.dictionary's I thought about writing my own hash table implementation in AutoIt, but on balance I decided it wasn't worth the effort and just stuck to Scripting.dictionary to save time/effort. As you can see I've got a decent number of unit tests for such a simple implementation, so it should be quite robust. #include <Dict2.au3> #include <Array.au3> $dict = _DictCreate() ConsoleWrite($dict.len()) ; Outputs 0 $dict.set("key1", "value1") $dict.set("key2", "value2") $dict.set("key3", "value3") $dict.set("key4", 1) ConsoleWrite($dict.get("key2")) ; Outputs 'value2' ConsoleWrite($dict.len()) ; Outputs 3 ConsoleWrite($dict.contains("key2") ; Outputs True $dict.set("key4", $dict.get("key4") + 1) ConsoleWrite($dict.get("key4")) ; Outputs 2 $dict.del("key4") ConsoleWrite($dict.contains("key4")) ; Outputs False $aPairs = $dict.pairs() _ArrayDisplay($aPairs) ; Displays 2d array with column one contains keys, and column two ; containing associated values $aKeys = $dict.keys() _ArrayDisplay($aKeys) ; Displays array containing all keys $aValues = $dict.values() _ArrayDisplay($aValues) ; Displays array of all values $aDesiredKeys = ["key1", "key3"] $aValues = $dict.values($aDesiredKeys) _ArrayDisplay($aValues) ; Displays array of values for key1 and key3 GET IT HERE
  2. Few days back i made an associative array UDF for a project as autoit does not have associative array/PHP style array support.it does not keep up to the quality of the example scripts posted in this forum. I hope it may be useful to other amateur developers like me. Main UDF file: associative_arrays.au3 CHM help file: associativearray_chm.zip list of main functions: _SetAssociativeArray() _AddAssociativeArray() _AssociativeArray() print_r() array2json() Json2Array() example script: #include <associative_arrays.au3> $datas = '' ; creates a variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; Associative_array exmples ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;first example: seting an array value $value = _SetAssociativeArray($datas, 'roger->royal->datar', '','changedatata=>>inprogressd', True) ConsoleWrite(@CR&'first example: seting an array value'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf $value = _AddAssociativeArray($datas, 'roger->royal->datar->0', -1, 'changedatata=>>inprogress', True) ;makes a sub array ConsoleWrite(@CR&'creating a non existent array path roger->royal->datar->0'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;second example: pushing an element to the end of an array $value = _AddAssociativeArray($datas, 'roger->royal->datar', -1, 'changedatata=>>inpro', True) ConsoleWrite(@CR&'second example: pushing an element to the end of an array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;third example: adding an element to the 2nd index position in the associative array $value = _AddAssociativeArray($datas, 'roger->royal->datar', 2, 'added element to 2nd position', True) ConsoleWrite(@CR&'third example: adding an element to the 2nd index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;fourth example: changing the element in the 2nd index position in the associative array $value = _SetAssociativeArray($datas, 'roger->royal->datar', 2, '2nd element changed') ConsoleWrite(@CR&'fourth example: changing the element in the 2nd index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;fifth example: changing the element in the first index position in the associative array $value = _SetAssociativeArray($datas, 'roger->royal->datar', 1, 'first element changed') ConsoleWrite(@CR&'fifth example: changing the element in the first index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf _SetAssociativeArray($datas, 'list', '', 'echo', True);makes another array in the root $value = _AssociativeArray($datas, 'roger->royal->datar') _ArrayDisplay($value, 'sixth example: reading an array at the position roger->royal->datar') ConsoleWrite(@CR & 'seventh example: reading the second element of an array'& @CR &_AssociativeArray($datas, 'roger->royal->datar', 2)) $value = _AssociativeArray($datas, 'roger->royal->data') _ArrayDisplay($value, 'eighth example: trying to read an array which doesnt exist') ;print_r($datas) $test_json = '{"0":"again0","1":"again1","5":{"0":"test1","male":["asf","s:dfs,f"," boo\r\n hoo"],"1":"test2","2":"test\t3","3":"dgdg \\n fdgd"},"6":"test4","7":"test5"}' $json_test_array = '' $value = Json2Array($json_test_array, $test_json) ConsoleWrite(@CR&'Converting a json to an associative array'&@CR) If $value > -1 Then print_r($json_test_array) Else ConsoleWrite("Failed: " & $value) EndIf ConsoleWrite(@crlf&'Converting an associative array to json'&@CR& array2json($json_test_array)&@CRLF) ConsoleWrite(Get_Ass_Array($json_test_array, '0', 0, True)&@CR) Do let me know if there are any bugs.. Thank you..
  3. I have a project where I wish to create a layout file for a drawing program using AutoIT. The format for this program is simple: header, objects (1..n), properties. Most of it, I have in control. But I need an idea about how best to add the objects. Here, an object has some properties such as coordinate, font etc. My idea is to call a function like add_object() which will add with default parameters. Now to my question: how can I "override" parameters in the function call ? I do not know which parameters will be overridden, this depends on user choices. So thereby I do not know the number of parameters in my function call. Do anyone have an idea about how to do achieve something like this, which is inspired from Perl ; pseudocode function call: add_object( 'xpos' => '123', 'font' => 'Arial', 'rotation' => '90' ) ; the remaining parameters will be default ; pseudo code func add_object(byref $paramsettings) $original = get_default_object() ; first load a default object type for each $key ($paramsettings) $original[$key] = $paramsettings[$key] ; override default here next write_out_object($original) ; now with modified original endfunc I have looked at but I am not 100% sure how to pass as an argument and (specifically) how to check which keys are passed ? (as in "for each $keys in $passed_array") Any help welcomed.
×
×
  • Create New...