Ranmaru

Dictionary Object in AutoIt?

18 posts in this topic

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.


Share this post


Link to post
Share on other sites



A dictionary object example.

Global $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

:whistle:

Share this post


Link to post
Share on other sites

Ty MHz, this is just what I needed.


Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

You can only store strings in the scripting dictionary.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by SkinnyWhiteGuy

Share this post


Link to post
Share on other sites

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"))

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!

:D


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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by ptrex

Share this post


Link to post
Share on other sites

Hi,

#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


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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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"))

Share this post


Link to post
Share on other sites

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

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