Sign in to follow this  
Followers 0
susall

how to get back object from Scripting.Dictionary's Item property

6 posts in this topic

I'm trying to understand the error message I'm getting back from AutoIT when I try to run this line of code:

C:\Documents and Settings\llewels\Desktop\AutoITScripts\ConfigCases.au3 (63) : ==> Variable must be of type "Object".:
$filename = $oDict.Item("Resultpath") & "\" & $frontdate & "_" & $caseID & "_" & $date & "_results.xml"

The variable $oDict is already set to the Scripting.Dictionary object. If the Item property returns an object, how would I declare $filename in AutoIT?

I'm running version 3.3.0.0. I've looked at other similar posts and they don't seem to solve this problem, either.

-su

Share this post


Link to post
Share on other sites



When I try it this way:

Dim $tmp = "Resultpath" & "\" & $frontdate & "_" & $caseID & "_" & $date & "_results.xml"
   $filename = $oDict.Item(tmp)

I see it's treating Item as a keyword of AutoIT, when it's a property of the Scripting.Dictionary object.

Share this post


Link to post
Share on other sites

When I try it this way:

Dim $tmp = "Resultpath" & "\" & $frontdate & "_" & $caseID & "_" & $date & "_results.xml"
   $filename = $oDict.Item(tmp)

I see it's treating Item as a keyword of AutoIT, when it's a property of the Scripting.Dictionary object.

The example above does not appear to be equivalent to what was written in the original post. Perhaps I'm missing some details, but does this resolve the issue?

Dim $tmp = "Resultpath" & "\" & $frontdate & "_" & $caseID & "_" & $date & "_results.xml"
   $filename = $oDict(tmp)

Share this post


Link to post
Share on other sites

The example above does not appear to be equivalent to what was written in the original post. Perhaps I'm missing some details, but does this resolve the issue?

Dim $tmp = "Resultpath" & "\" & $frontdate & "_" & $caseID & "_" & $date & "_results.xml"
   $filename = $oDict(tmp)

You're right... I was trying to get down to the bottom of why Scripting Dictionary doesn't work. I haven't solved it yet. But the Item member of Dictionary object is color-coded by the Script-Editor as though it was an AutoIT keyword. -su

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You could try these wrapper functions

#include <Array.au3>

Func _AssocArray()
    Local $aArray = ObjCreate("Scripting.Dictionary")
    If @error Then
        Return SetError(1, 0, 0)
    EndIf
    $aArray.CompareMode = 1
    Return $aArray
EndFunc   ;==>_AssocArray

Func _AssocArrayDestroy(ByRef $aArray)
    If Not IsObj($aArray) Then
        Return False
    EndIf
    $aArray.RemoveAll()
    $aArray = 0
    Return True
EndFunc   ;==>_AssocArrayDestroy

The Item property is the default so don't even state it. Use something like this:

$aArray = _AssocArray()
$aArray("ResultPath") = "C:\SomePath"
$path = $aArray("ResultPath") & "\yaddayadda"
;when done destroy array
_AssocArrayDestroy($aArray)
Edited by MilesAhead

Share this post


Link to post
Share on other sites

wrappers or not

Variable must be of type "Object".: $filename = $oDict.Item("Resultpath")
means that $oDict is not an object and therefore does not contain a dictionary object

$oDict=ObjCreate("Scripting.Dictionary")
$oDict.Item("Resultpath")='C:\SomePath'
MsgBox(0 , "Test" , $oDict("Resultpath"))

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

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