Sign in to follow this  
Followers 0
b47chguru

Associative array UDF

10 posts in this topic

#1 ·  Posted (edited)

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..

Edited by b47chguru

Share this post


Link to post
Share on other sites



You're using Dim in the functions, you shouldn't. Especially since the variable names that you're using it with are fairly common names and I can easily foresee a name clash if someone declared a global with the same name. You should always check your script with this directive in it to see if there are any issues.

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 6

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

 

You're using Dim in the functions, you shouldn't. Especially since the variable names that you're using it with are fairly common names and I can easily foresee a name clash if someone declared a global with the same name. You should always check your script with this directive in it to see if there are any issues.

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 6

Thankyou brewman for the reply,

i am new to autoit.can you show with an example how using dim on a variable declared locally in a function change it if declared globally later...

 

Share this post


Link to post
Share on other sites

AutoIt beta help file!

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w- 3 -w- 6 ; already declared var=off , warn when using Dim=off

#include <Constants.au3>

Dim $vVariableThatIsGlobal = "This is a variable that has ""Program Scope"" aka Global."

MsgBox($MB_SYSTEMMODAL, "", "An example of why Dim can cause more problems than solve them.")

Example()

Func Example()
    ; That looks alright to me as it displays the following text: This is a variable that has "Program Scope" aka Global.
    MsgBox($MB_SYSTEMMODAL, "", $vVariableThatIsGlobal)

    ; Call some random function.
    Local $vReturn = SomeFunc()

    ; The Global variable ($vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in "SomeFunc".
    MsgBox($MB_SYSTEMMODAL, $vReturn, "The variable has now changed: " & $vVariableThatIsGlobal)
EndFunc   ;==>Example

Func SomeFunc()
    ; This should create a variable in Local scope if the variable name doesn"t already exist.
    ; For argument sake I totally forgot that I declared a variable already with the same name.
    ; Well I only want this to be changed in the function and not the variable at the top of the script.
    ; Should be OK right? Think again.
    Dim $vVariableThatIsGlobal = ""

    For $i = 1 To 10
        $vVariableThatIsGlobal &= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.
    Next
    Return $vVariableThatIsGlobal
EndFunc   ;==>SomeFunc

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I'm wondering did you test you own example and did it work for you?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

 

AutoIt beta help file!

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w- 3 -w- 6 ; already declared var=off , warn when using Dim=off

#include <Constants.au3>

Dim $vVariableThatIsGlobal = "This is a variable that has ""Program Scope"" aka Global."

MsgBox($MB_SYSTEMMODAL, "", "An example of why Dim can cause more problems than solve them.")

Example()

Func Example()
    ; That looks alright to me as it displays the following text: This is a variable that has "Program Scope" aka Global.
    MsgBox($MB_SYSTEMMODAL, "", $vVariableThatIsGlobal)

    ; Call some random function.
    Local $vReturn = SomeFunc()

    ; The Global variable ($vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in "SomeFunc".
    MsgBox($MB_SYSTEMMODAL, $vReturn, "The variable has now changed: " & $vVariableThatIsGlobal)
EndFunc   ;==>Example

Func SomeFunc()
    ; This should create a variable in Local scope if the variable name doesn"t already exist.
    ; For argument sake I totally forgot that I declared a variable already with the same name.
    ; Well I only want this to be changed in the function and not the variable at the top of the script.
    ; Should be OK right? Think again.
    Dim $vVariableThatIsGlobal = ""

    For $i = 1 To 10
        $vVariableThatIsGlobal &= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal.
    Next
    Return $vVariableThatIsGlobal
EndFunc   ;==>SomeFunc

 

I'm wondering did you test you own example and did it work for you?

 

 

Hi guinness, first of all sorry for the late reply..

and thanks for the example, i get the point...but is there any alternative to Dim?

yes i have tested and my example works perfectly..

i am using autoit version v3.3.6.1

Share this post


Link to post
Share on other sites

i am using autoit version v3.3.6.1

Well the majority of us are using v3.3.8.1 (as well as the beta) and I don't think it does, because _ArrayDisplay requires a variable to be passed as a reference. Unless _ArrayDisplay was coded differently in that version?

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

yes _ArrayDisplay function in this version also requires array passed as reference but somehow it works even if it is not supplied in that way...

_ArrayDisplay(Const ByRef $avArray [, $sTitle = "Array: ListView Display" [, $iItemLimit = -1 [, $iTranspose = 0 [, $sSeparator = "" [, $sReplace = "|" [, $sHeader = ""]]]]]])

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

That's a bug then that was fixed in v3.3.8.1, strange as I didn't see anything in the changelog. Anyway, I'm just telling you the example doesn't work for those of us who use the current version.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

ok :)
modified the example code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • therms
      By therms
      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
    • Myicq
      By Myicq
      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.