Ranmaru Posted July 17, 2007 Share Posted July 17, 2007 Is there anything in AutoIt like the Dictionary Object in VBS? Arrays are nothing like it so please don't say arrays. Thanks in advance. Link to comment Share on other sites More sharing options...
MHz Posted July 17, 2007 Share Posted July 17, 2007 A dictionary object example. expandcollapse popupGlobal $vKey, $sItem, $sMsg, $oDictionary ; Create dictionary object $oDictionary = ObjCreate("Scripting.Dictionary") If @error Then MsgBox(0, '', 'Error creating the dictionary object') Else ; Add keys with items $oDictionary.Add ("One", "Same" ) $oDictionary.Add ("Two", "Car" ) $oDictionary.Add ("Three", "House" ) $oDictionary.Add ("Four", "Boat" ) If $oDictionary.Exists('One') Then ; Display item MsgBox(0x0, 'Item One', $oDictionary.Item('One'), 2) ; Set an item $oDictionary.Item('One') = 'Changed' ; Display item MsgBox(0x20, 'Did Item One Change?', $oDictionary.Item('One'), 3) ; Remove key $oDictionary.Remove('One') ; $oDictionary.Key ('Two') = 'Bike' EndIf Sleep(1000) ; Store items into a variable For $vKey In $oDictionary $sItem &= $oDictionary.Item($vKey) & @CRLF Next ; Display items MsgBox(0x0, 'Items Count: ' & $oDictionary.Count, $sItem, 3) ; Add items into an array $aItems = $oDictionary.Items ; Display items in the array For $i = 0 To $oDictionary.Count -1 MsgBox(0x0, 'Items [ ' & $i & ' ]', $aItems[$i], 2) Next Sleep(1000) ; Add keys into an array $aKeys = $oDictionary.Keys ; Display keys in the array For $i = 0 To $oDictionary.Count -1 MsgBox(0x0, 'Keys [ ' & $i & ' ]', $aKeys[$i], 2) Next EndIf Professor_Bernd and YellowAfterlife 2 Link to comment Share on other sites More sharing options...
James Posted July 17, 2007 Share Posted July 17, 2007 There are a few spell checkers that use Word UDF Mrbond, has created a brute hacker and password gen, that uses a dictionary! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Ranmaru Posted July 17, 2007 Author Share Posted July 17, 2007 Ty MHz, this is just what I needed. Link to comment Share on other sites More sharing options...
aGorilla Posted April 14, 2008 Share Posted April 14, 2008 The Scripting.Dictionary is a wonderful thing, and it's holding about 50 (formerly global) variables for me (thanks to weaponx for pointing it out). I've run into two places where it doesn't seem to play well, and the behavior it causes is quite unpredictable. For some strange reason, they don't like being on the receiving end of either _IECreateEmbedded(), or GUICreate(). I'm quite new to AutoIt, so I may be misdiagnosing this problem. All I know is that when I switched those back to normal globals, my errors went away. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
weaponx Posted April 14, 2008 Share Posted April 14, 2008 You can only store strings in the scripting dictionary. Link to comment Share on other sites More sharing options...
aGorilla Posted April 14, 2008 Share Posted April 14, 2008 Oddly enough, it seemed to work half the time, just enough to make me think it was something else. I think I was also fooled by the fact that I could store the return from GUICtrlCreateInput - I thought that would return an object, but apparently it just returns an id. Lesson learned, and since I learned it the hard way, I'm less likely to forget. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted April 14, 2008 Share Posted April 14, 2008 (edited) You can only store strings in the scripting dictionary. Um, I can successfully store an Array in a scripting dictionary, and retrieve that array. Local $objDic = ObjCreate("Scripting.Dictionary") Local $arArray[3], $i $arArray[0] = "This is" $arArray[1] = " a " $arArray[2] = "test." $objDic("FINDME") = $arArray $arArray = 0 Local $arNewArray = $objDic("FINDME") For $i = 0 To 2 ConsoleWrite($arNewArray[$i]) Next ConsoleWrite(@CRLF) Edited April 14, 2008 by SkinnyWhiteGuy Link to comment Share on other sites More sharing options...
weaponx Posted April 14, 2008 Share Posted April 14, 2008 So arrays are allowed as well, but objects can't be stored within the dictionary. Dim $obj1 = ObjCreate("Scripting.Dictionary") Dim $obj2 = ObjCreate("Scripting.Dictionary") Dim $obj3 = ObjCreate("Scripting.Dictionary") Local $arArray[3], $i $obj2("TEST") = "PASSWORD" $obj1("OBJECT") = $obj2 ; FAIL $var = $obj1("OBJECT") MsgBox(0,"",$var("TEST")) Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted April 15, 2008 Share Posted April 15, 2008 Yeah, I discovered that too, but, as just a hunch, I also discovered that, if you nest the object in an array, you can recurse them. So, if you go Obj->Array->Obj, you can do that. You just can't easily reference them, and you start having to have temp variables to pull the arrays back out, do what you need, then insert them back into the object. However, I recently found that, if you have an Array of Dictionary objects, you can reference them quite nicely: Dim $arArray[3] For $i = 0 To 2 $arArray[$i] = ObjCreate("Scripting.Dictionary") Next $arArray[0]("a") = "This is" $arArray[1]("b") = " a test." $arArray[2]("c") = " BOOYA!" For $i = 0 To 2 ConsoleWrite($arArray[$i](Chr($i + 97))) Next ConsoleWrite(@CRLF) I recently used this in an App in place of a multi-dimensioned Array simply because I could easily assign & read variables with a descriptive name, so I could find where I was and what I was doing a lot faster (which helped in the 2000 line script). I know that I could have near the same thing by using a Global Enum and using those Variable names as my description, but this made it easier for me to add new variables, and it was also just a test to see if it would really work like this. I liked it, no worrying about was the header right with my Enum, I could add a new property when I needed it, etc... Just wanted others to know, this made for a very fast and easy to use Database-type variable. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 15, 2008 Share Posted April 15, 2008 However, I recently found that, if you have an Array of Dictionary objects, you can reference them quite nicely: Dim $arArray[3] For $i = 0 To 2 $arArray[$i] = ObjCreate("Scripting.Dictionary") Next $arArray[0]("a") = "This is" $arArray[1]("b") = " a test." $arArray[2]("c") = " BOOYA!" For $i = 0 To 2 ConsoleWrite($arArray[$i](Chr($i + 97))) Next ConsoleWrite(@CRLF) Ooh, cool! Shiny new toy! Thanks for the tip SkinnyWhiteGuy! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
aGorilla Posted April 15, 2008 Share Posted April 15, 2008 Thanks for pointing that out. When I stumbled on the dictionary object, I was looking for a hash, because I really didn't want to deal with arrays. But I have to admit, that's a pretty clever mix of the two. I could handle an array on small scales (like your example), and it lets me 'group' the data... 1 is for internals, 2 is for menus, 3 is for forms, 4 is for user data, etc. Something like that would be tolerable, and let's you pass them around in smaller sets. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
ptrex Posted April 15, 2008 Share Posted April 15, 2008 (edited) @weaponx This is how you would add an object to the dictionary. Dim $obj1 = ObjCreate("Scripting.Dictionary") Dim $obj2 = ObjCreate("Scripting.Dictionary") Dim $obj3 = ObjCreate("Scripting.Dictionary") $obj2("TEST") = "PASSWORD" ConsoleWrite("Object 2 : " & $obj2.item("TEST") & @LF) $obj1("OBJECT") = $obj2.item("TEST") ; DOES NOT FAIL $var = $obj1("OBJECT") ConsoleWrite("Object2 in Object1 : " & $obj1.item("OBJECT") & @LF) regards ptrex Edited April 15, 2008 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 15, 2008 Share Posted April 15, 2008 Hi, expandcollapse popup#cs ============================= OBJEKT 'Scripting.Dictionary' ======================================= *** Funktionssammlung *** _ObjDictCreate(Modus) Erzeugt ein Dictionary Objekt im Binär- (default) oder Textmodus Gibt das Handle des Objektes zurĂ¼ck _ObjDictAdd(Objekt, SchlĂ¼ssel, Wert) FĂ¼gt einem Dictionary Objekt ein SchlĂ¼ssel-Wert Paar hinzu _ObjDictGetValue(Objekt, SchlĂ¼ssel) Liest den Wert fĂ¼r einen SchlĂ¼ssel aus _ObjDictSetValue(Objekt, SchlĂ¼ssel) Setzt einen neuen Wert fĂ¼r einen SchlĂ¼ssel _ObjDictCount(Objekt) Gibt die Anzahl der SchlĂ¼ssel-Wert Paare zurĂ¼ck _ObjDictSearch(Objekt, SchlĂ¼ssel) PrĂ¼ft ob der SchlĂ¼ssel existiert, liefert 'TRUE' wenn gefunden _ObjDictDeleteKey(Objekt, SchlĂ¼ssel) Löscht den angegebenen SchlĂ¼ssel (und dessen Wert) Wird statt eines SchlĂ¼sselnamens '' Ă¼bergeben, werden alle SchlĂ¼ssel gelöscht (Standard) _ObjDictList(Objekt) Eine GUI mit einem ListView zeigt alle SchlĂ¼ssel-Wert Paare _IniReadSectionToObjDict(Objekt, INI-Pfad, Sektion) Liest die angegebene INI-Sektion in das Objekt Gibt die Anzahl der gelesenen SchlĂ¼ssel-Wert Paare zurĂ¼ck _IniWriteSectionFromObjDict(Objekt, INI-Pfad, Sektion) Schreibt die SchlĂ¼ssel-Wert Paare des Objekts in die angegebene Sektion der INI-Datei Gibt die Anzahl der geschriebenen SchlĂ¼ssel-Wert Paare zurĂ¼ck _FileReadToObjDict(Objekt, TextDatei-Pfad, Seperator) Liest aus einer Textdatei alle SchlĂ¼ssel-Wert Paare zeilenweise ein (1 Paar/Zeile) Standard-Seperator ist '|', kann hier angepaĂŸt werden Gibt die Anzahl der gelesenen SchlĂ¼ssel-Wert Paare zurĂ¼ck _FileWriteFromObjDict(Objekt, TextDatei-Pfad, Seperator, Overwrite) Schreibt die SchlĂ¼ssel-Wert Paare des Objekts in die angegebene Datei (1 Paar/Zeile). Mit Overwrite='TRUE' (Standard) wird die angegebene Datei, falls sie bereits existiert, Ă¼berschrieben. Mit 'FALSE' wird an eine bestehende Datei angehängt. Standard-Seperator ist '|', kann hier angepaĂŸt werden. Gibt die Anzahl der geschriebenen SchlĂ¼ssel-Wert Paare zurĂ¼ck Autor: BugFix ( bugfix@autoit.de ) =================================================================================================== #ce #include <GuiConstants.au3> #include <GuiListView.au3> ;================================================================================================== ; Parameter: $MODE ; 0 Binär (default) ; 1 Text ; Return: Objekt Handle ;================================================================================================== Func _ObjDictCreate($MODE=0) $oDICT = ObjCreate('Scripting.Dictionary') If $MODE <> 0 Then $oDICT.CompareMode = 1 Return $oDICT EndFunc ;==>_ObjDictCreate ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $KEY - SchlĂ¼ssel ; $VALUE - Wert ; Return: Erfolg: 0 ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 2 SchlĂ¼ssel ohne Inhalt Ă¼bergeben ; 3 Wert hat keinen Inhalt ; 4 SchlĂ¼ssel bereits vorhanden ;================================================================================================== Func _ObjDictAdd(ByRef $oDICT, $KEY, $VALUE) If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf $KEY = '' Then SetError(2) Return -1 ElseIf $VALUE = '' Then SetError(3) Return -1 ElseIf $oDICT.Exists($KEY) Then SetError(4) Return -1 EndIf $oDICT.Add($KEY, $VALUE) Return 0 EndFunc ;==>_ObjDictAdd ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $KEY - SchlĂ¼ssel ; Return: Erfolg: Wert des SchlĂ¼ssels ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 2 SchlĂ¼ssel ohne Inhalt Ă¼bergeben ; 5 SchlĂ¼ssel nicht vorhanden ;================================================================================================== Func _ObjDictGetValue(ByRef $oDICT, $KEY) If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf $KEY = '' Then SetError(2) Return -1 ElseIf Not $oDICT.Exists($KEY) Then SetError(5) Return -1 EndIf Return $oDICT.Item($KEY) EndFunc ;==>_ObjDictGetValue ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $KEY - SchlĂ¼ssel ; $VALUE - Wert ; Return: Erfolg: 0 ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 2 SchlĂ¼ssel ohne Inhalt Ă¼bergeben ; 3 Wert hat keinen Inhalt ; 5 SchlĂ¼ssel nicht vorhanden ;================================================================================================== Func _ObjDictSetValue(ByRef $oDICT, $KEY, $VALUE) If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf $KEY = '' Then SetError(2) Return -1 ElseIf $VALUE = '' Then SetError(3) Return -1 ElseIf Not $oDICT.Exists($KEY) Then SetError(5) Return -1 EndIf $oDICT.Item($KEY) = $VALUE Return 0 EndFunc ;==>_ObjDictSetValue ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; Return: Erfolg: Anzahl der SchlĂ¼ssel-Wert Paare ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ;================================================================================================== Func _ObjDictCount(ByRef $oDICT) If Not IsObj($oDICT) Then SetError(1) Return -1 EndIf Return $oDICT.Count EndFunc ;==>_ObjDictCount ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $KEY - SchlĂ¼ssel ; Return: Erfolg: TRUE SchlĂ¼ssel vorhanden ; FALSE SchlĂ¼ssel nicht vorhanden ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 2 SchlĂ¼ssel ohne Inhalt Ă¼bergeben ;================================================================================================== Func _ObjDictSearch(ByRef $oDICT, $KEY) If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf $KEY = '' Then SetError(2) Return -1 ElseIf Not $oDICT.Exists($KEY) Then Return False Else Return True EndIf EndFunc ;==>_ObjDictSearch ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $KEY - SchlĂ¼ssel (default='') ; mit $KEY = '' werden alle SchlĂ¼ssel gelöscht ; Return: Erfolg: 0 ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ;================================================================================================== Func _ObjDictDeleteKey(ByRef $oDICT, $KEY='') If Not IsObj($oDICT) Then SetError(1) Return -1 EndIf If $KEY = '' Then $oDICT.RemoveAll Return 0 ElseIf Not $oDICT.Exists($KEY) Then SetError(5) Return -1 EndIf $oDICT.Remove($KEY) Return 0 EndFunc ;==>_ObjDictDeleteKey ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $TITLE - Fenstertitel (optional) ; Return: Erfolg: GUI mit ListView ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; Requirements: #include <GuiConstants.au3> ; #include <GuiListView.au3> ;================================================================================================== Func _ObjDictList(ByRef $oDICT, $TITLE='Elemente: Objekt Dictionary') If Not IsObj($oDICT) Then SetError(1) Return -1 EndIf Local $count = $oDICT.Count Local $SaveMode = Opt("GUIOnEventMode",0), $ListGUI, $oDictLV, $btnClose, $msg $ListGUI = GUICreate($TITLE, 600, 400, (@DesktopWidth - 600)/2, (@DesktopHeight - 400)/2) $btnClose = GUICtrlCreateButton('&Ende', 40, 360, 70, 22) GUICtrlSetResizing($btnClose, BitOR($GUI_DockRight, $GUI_DockBottom, $GUI_DockSize)) GUICtrlDelete($oDictLV) $oDictLV = GUICtrlCreateListView('SchlĂ¼ssel|Wert', 10, 10, 580, 340, BitOR($LVS_SHOWSELALWAYS, _ $LVS_EDITLABELS), BitOR($LVS_EX_GRIDLINES, $LVS_EX_HEADERDRAGDROP, $LVS_EX_FULLROWSELECT, $LVS_EX_REGIONAL)) If $count > 0 Then Local $strKey, $colKeys = $oDICT.Keys For $strKey In $colKeys GUICtrlCreateListViewItem($strKey & '|' & $oDICT.Item($strKey), $oDictLV) Next Else WinSetTitle($ListGUI, '', 'Das Objekt Dictionary enthält keine Elemente!') EndIf GUISetState(@SW_SHOW, $ListGUI) While 1 $msg = GUIGetMsg(1) If $msg[1] = $ListGUI And _ ($msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $btnClose) Then ExitLoop WEnd GUIDelete($ListGUI) Opt("GUIOnEventMode",$SaveMode) EndFunc ;==>ObjDictList ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $PathINI - Pfad der INI-Datei ; $SECTION - Sektion die gelesen werden soll ; Return: Erfolg: Anzahl der eingelesenen SchlĂ¼ssel-Wert Paare ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 6 INI-Pfad nicht vorhanden ; 7 kein Sektionsname ; 8 INI-Sektion konnte nicht gelesen werden oder leer ;================================================================================================== Func _IniReadSectionToObjDict(ByRef $oDICT, $PathINI, $SECTION) If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf Not FileExists($PathINI) Then SetError(6) Return -1 ElseIf $SECTION = '' Then SetError(7) Return -1 EndIf Local $arSECTION = IniReadSection($PathINI, $SECTION) If Not IsArray($arSECTION) Then SetError(8) Return -1 EndIf For $i = 1 To $arSECTION[0][0] $oDICT.Add($arSECTION[$i][0], $arSECTION[$i][1]) Next Return $arSECTION[0][0] EndFunc ;==>_IniReadSectionToObjDict ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $PathINI - Pfad der INI-Datei ; $SECTION - Sektion die gelesen werden soll ; Return: Erfolg: Anzahl der geschriebenen SchlĂ¼ssel-Wert Paare ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 7 kein Sektionsname ; 9 INI-Sektion konnte nicht geschrieben werden ;================================================================================================== Func _IniWriteSectionFromObjDict(ByRef $oDICT, $PathINI, $SECTION) If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf $SECTION = '' Then SetError(7) Return -1 EndIf Local $arSECTION[$oDICT.Count][2], $i = 0 Local $strKey, $colKeys = $oDICT.Keys For $strKey In $colKeys $arSECTION[$i][0] = $strKey $arSECTION[$i][1] = $oDICT.Item($strKey) $i += 1 Next If IniWriteSection($PathINI, $SECTION, $arSECTION, 0) = 1 Then Return $oDICT.Count Else SetError(9) Return -1 EndIf EndFunc ;==>_IniWriteSectionFromObjDict ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $PathFile - Pfad der Datei ; $SEPERATOR - Trennzeichen zwischen Wert u. SchlĂ¼ssel, Standard: '|' ; Return: Erfolg: Anzahl der eingelesenen SchlĂ¼ssel-Wert Paare ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 6 Datei-Pfad nicht vorhanden ; 7 Leerstring als Seperator Ă¼bergeben ; 8 Datei konnte nicht gelesen werden ;================================================================================================== Func _FileReadToObjDict(ByRef $oDICT, $PathFile, $SEPERATOR='|') If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf Not FileExists($PathFile) Then SetError(6) Return -1 ElseIf $SEPERATOR = '' Then SetError(7) Return -1 EndIf Local $fh = FileOpen($PathFile, 0), $line Local $val If $fh = -1 Then SetError(8) Return -1 EndIf While 1 $line = FileReadLine($fh) If @error = -1 Then ExitLoop $val = StringSplit($line, $SEPERATOR) If $val[0] > 1 Then $oDICT.Add($val[1], $val[2]) EndIf Wend FileClose($fh) Return $oDICT.Count EndFunc ;==>_FileReadToObjDict ;================================================================================================== ; Parameter: $oDICT - Handle des Dictionary-Objektes ; $PathFile - Pfad der Datei ; $SEPERATOR - Trennzeichen zwischen Wert u. SchlĂ¼ssel, Standard: '|' ; $OVERWRITE - Falls Datei existiert, wird sie Ă¼berschrieben (Standard). ; Mit 'FALSE' wird an bestehende Datei angehängt. ; Return: Erfolg: Anzahl der geschriebenen SchlĂ¼ssel-Wert Paare ; Fehler: -1 ; Fehlerwert: 1 Objekt existiert nicht ; 7 Leerstring als Seperator Ă¼bergeben ; 8 Datei konnte nicht geschrieben werden ;================================================================================================== Func _FileWriteFromObjDict(ByRef $oDICT, $PathFile, $SEPERATOR='|', $OVERWRITE=True) If Not IsObj($oDICT) Then SetError(1) Return -1 ElseIf $SEPERATOR = '' Then SetError(7) Return -1 EndIf If $OVERWRITE Then Local $fh = FileOpen($PathFile, 34) Else Local $fh = FileOpen($PathFile, 33) EndIf Local $strKey, $colKeys = $oDICT.Keys For $strKey In $colKeys FileWriteLine($fh, $strKey & $SEPERATOR & $oDICT.Item($strKey)) If @error Then SetError(8) Return -1 EndIf Next FileClose($fh) Return $oDICT.Count EndFunc ;==>_FileWriteFromObjDict Mega Professor_Bernd 1 Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-CafĂ© Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
randallc Posted April 15, 2008 Share Posted April 15, 2008 Yeah, I discovered that too, but, as just a hunch, I also discovered that, if you nest the object in an array, you can recurse them. So, if you go Obj->Array->Obj, you can do that. You just can't easily reference them, and you start having to have temp variables to pull the arrays back out, do what you need, then insert them back into the object. However, I recently found that, if you have an Array of Dictionary objects, you can reference them quite nicely: Dim $arArray[3] For $i = 0 To 2 $arArray[$i] = ObjCreate("Scripting.Dictionary") Next $arArray[0]("a") = "This is" $arArray[1]("b") = " a test." $arArray[2]("c") = " BOOYA!" For $i = 0 To 2 ConsoleWrite($arArray[$i](Chr($i + 97))) Next ConsoleWrite(@CRLF) I recently used this in an App in place of a multi-dimensioned Array simply because I could easily assign & read variables with a descriptive name, so I could find where I was and what I was doing a lot faster (which helped in the 2000 line script). I know that I could have near the same thing by using a Global Enum and using those Variable names as my description, but this made it easier for me to add new variables, and it was also just a test to see if it would really work like this. I liked it, no worrying about was the header right with my Enum, I could add a new property when I needed it, etc... Just wanted others to know, this made for a very fast and easy to use Database-type variable.omg! great m8 ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
weaponx Posted April 15, 2008 Share Posted April 15, 2008 @weaponx This is how you would add an object to the dictionary. Dim $obj1 = ObjCreate("Scripting.Dictionary") Dim $obj2 = ObjCreate("Scripting.Dictionary") Dim $obj3 = ObjCreate("Scripting.Dictionary") $obj2("TEST") = "PASSWORD" ConsoleWrite("Object 2 : " & $obj2.item("TEST") & @LF) $obj1("OBJECT") = $obj2.item("TEST") ; DOES NOT FAIL $var = $obj1("OBJECT") ConsoleWrite("Object2 in Object1 : " & $obj1.item("OBJECT") & @LF) regards ptrex That isn't actually adding the second object as a member of the first object, that merely copies a single element. Link to comment Share on other sites More sharing options...
aGorilla Posted April 17, 2008 Share Posted April 17, 2008 Ok, I just got bitten by case sensitivity. I had set a value for 'UserId', but tried to access it with 'UserID' (notice the uppercase 'D'). It failed, silently.The good news is, there's a solution. The scripting dictionary has an option to compare keys by 'text' (not case sensitive), or by 'binary' (which is case sensitive). It looks like the default is 'binary', but you can change that.Here's an example - Note: You have to set the CompareMode before you add any values.Dim $obj1 = ObjCreate("Scripting.Dictionary") $Obj1.CompareMode = 0; binary - case sensitive. $Obj1.Add('KeY_NaMe', 'some value') Dim $obj2 = ObjCreate("Scripting.Dictionary") $Obj2.CompareMode = 1; text - NOT case sensitive. $Obj2.Add('KeY_NaMe', 'some value') MsgBox(0, "KeY_NaMe", $Obj1.Item("KeY_NaMe")) MsgBox(0, "key_name", $Obj1.Item("key_name")); blank MsgBox(0, "KeY_NaMe", $Obj2.Item("KeY_NaMe")) MsgBox(0, "key_name", $Obj2.Item("key_name")) Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 17, 2008 Share Posted April 17, 2008 Hi, already here: ;================================================================================================== ; Parameter: $MODE ; 0 Binär (default) ; 1 Text ; Return: Objekt Handle ;================================================================================================== Func _ObjDictCreate($MODE=0) $oDICT = ObjCreate('Scripting.Dictionary') If $MODE <> 0 Then $oDICT.CompareMode = 1 Return $oDICT EndFunc;==>_ObjDictCreate Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now