Ju72 Posted May 31, 2010 Share Posted May 31, 2010 Hi,I use PocketXML-RPC for send requests to an XML-RPC server.I have a problem with this ligne : $b = $response."711".name ;Error referenced outside a "With" statement.When I execute the script I have this error : Error referenced outside a "With" statement.I have wrote the same code in php (with COM) and no problem, I can access to the value.I don't know how solve this problem. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- Func Connect () Dim $data[50] Dim $response[50] $f = ObjCreate("pocketXMLRPC.Factory") $p = $f.Proxy("http://localhost/testlink/lib/api/xmlrpc.php", "tl.") $r = $p.ping() ;ping the server MsgBox(4096, "Web Service Response", $r, 10) ;ok $myStruct = ObjCreate("PocketXMLRPC.Struct") $myStruct.devKey = "6e532660fab75f7057d3b753a04eac3c" $myStruct.testplanid = 709; $myStruct.testcasename = "tcTestJu" $response = $p.getTestCaseIDByName($myStruct) ;ok MsgBox(0,"",$response[0].id) ;$response[0].id = 711 $response = $p.getTestCasesForTestPlan($myStruct) $b = $response."711".name ;Error referenced outside a "With" statement. MsgBox(0,"",$b) EndFunc Connect ()For help the response in php:expandcollapse popupPOST /testlink/lib/api/xmlrpc.php HTTP/1.0 Host: localhost Content-Type: text/xml User-Agent: Incutio XML-RPC Content-length: 342 <?xml version="1.0"?> <methodCall> <methodName>tl.getTestCasesForTestPlan</methodName> <params> <param><value><struct> <member><name>devKey</name><value><string>6e532660fab75f7057d3b753a04eac3c</string></value></member> <member><name>testplanid</name><value><int>709</int></value></member> </struct></value></param> </params></methodCall> <?xml version="1.0"?> <methodResponse> <params> <param> <value> <struct> <member><name>711</name><value><struct> <member><name>testsuite_id</name><value><string>710</string></value></member> <member><name>summary</name><value><string></string></value></member> <member><name>steps</name><value><string></string></value></member> <member><name>expected_results</name><value><string></string></value></member> <member><name>tsuite_name</name><value><string>tsTestJu</string></value></member> <member><name>tc_id</name><value><string>711</string></value></member> <member><name>z</name><value><string>100</string></value></member> <member><name>name</name><value><string>tcTestJu</string></value></member> <member><name>tcversion_id</name><value><string>712</string></value></member> <member><name>feature_id</name><value><string>195</string></value></member> <member><name>execution_order</name><value><string>1</string></value></member> <member><name>version</name><value><string>1</string></value></member> <member><name>active</name><value><string>1</string></value></member> <member><name>external_id</name><value><string>311</string></value></member> <member><name>execution_type</name><value><string>2</string></value></member> <member><name>exec_id</name><value><string></string></value></member> <member><name>tcversion_number</name><value><string></string></value></member> <member><name>executed</name><value><string></string></value></member> <member><name>exec_on_tplan</name><value><string></string></value></member> <member><name>execution_run_type</name><value><string></string></value></member> <member><name>user_id</name><value><string></string></value></member> <member><name>type</name><value><string></string></value></member> <member><name>status</name><value><string></string></value></member> <member><name>assigner_id</name><value><string></string></value></member> <member><name>urgency</name><value><string>2</string></value></member> <member><name>exec_status</name><value><string>n</string></value></member> </struct></value></member> </struct> </value> </param> </params> </methodResponse>Thanks Link to comment Share on other sites More sharing options...
daluu Posted May 31, 2010 Share Posted May 31, 2010 This was the best I found, for error similar to yours: http://www.autoitscript.com/forum/index.php?showtopic=26505&st=0 Perhaps it is a COM error, and AutoIt is reporting the error with a vague message. In the meantime, since AutoIt is very similar to VBScript and you are not using anything feature specific to AutoIt, perhaps you can port your code into VBScript and run that and see if it works or what error message you get. Link to comment Share on other sites More sharing options...
Ju72 Posted June 1, 2010 Author Share Posted June 1, 2010 Thanks for your reply. I don't know VBScript but if I find the time I will try. I have port this code into php and I have no error, I think it's not a COM error. Link to comment Share on other sites More sharing options...
daluu Posted June 1, 2010 Share Posted June 1, 2010 Personally, I find COM error handling (at least in the case where other languages like VBScript, and AutoIt fail to catch COM errors) is best handled by JScript (on Windows Scripting Host (WSH) or Javascript in general). If you know JScript, you could port your code into JScript running as WSH script and see how that goes, catching COM error in your code using the try/catch block in JScript around your code. Link to comment Share on other sites More sharing options...
Ju72 Posted June 2, 2010 Author Share Posted June 2, 2010 Yes I think too that the error message is not clear. If it's ok in php there is no reason for have a problem with vb or jscript. Maybe it's a parse problem with AutoIt. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 2, 2010 Share Posted June 2, 2010 The error is actually due to you trying to use a string as an object. If you are trying to get a property named 771, I don't think that's even valid. Link to comment Share on other sites More sharing options...
daluu Posted June 2, 2010 Share Posted June 2, 2010 Ju72, it may be useful to post the PHP version of the code where you use the COM object to compare. Perhaps PHP is more flexible in how you call COM object properties/methods compared to AutoIt, like in the case of "711" property as Richard mentions. Richard, any ideas how to access property "711" in this case then? I don't work with XML-RPC myself, but I guess it's just accessing the "711" node branch from the PHP response output returned? Using XML DOM navigation and/or XPath, something like that? Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 2, 2010 Share Posted June 2, 2010 As far as I know, AutoIt can't call things like that due to the structure of the language. It doesn't even sound like a valid property name in the first place though. I actually don't have much experience in COM, but from other languages, I have seen that identifiers shouldn't start with numbers. Link to comment Share on other sites More sharing options...
Ju72 Posted June 3, 2010 Author Share Posted June 3, 2010 Hi, Thanks for your help. My code in php: <?php $f = new COM("pocketXMLRPC.Factory"); $p = $f->Proxy("http://localhost/testlink/lib/api/xmlrpc.php", "tl."); $r = $p->ping(); echo $r; $Struct = new COM("PocketXMLRPC.Struct"); $TabReponse = array (); $Struct->devKey = "6e532660fab75f7057d3b753a04eac3c"; $Struct->testplanid = 709; $TabReponse = $p->getTestCasesForTestPlan($Struct); $a = "711"; echo $TabReponse->$a->name; //Print the result ?> NB This code works: $a = "711"; echo $TabReponse->$a->name; //Print the result This code doesn't works: echo $TabReponse->"711"->name; //Print the result Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in D:\wamp\www\testCOM.php on line 41 I have try that with AutoIt $a = "711" $b = $response.$a.name But I have an error: $b =^ERROR Error: Error in expression. And this Dim $a[1] $a[0] = "711" $b = $response.$a[0].name But: $b = $reponse.$a[0]^ERROR Error referenced outside a "With" statement. I have found this link: COM Reference Can you tell me if this can help me: WITH..ENDWITH The WITH/ENDWITH statement does not add functionality, but it makes your script easier to read. For instance, the previous example using Excel can also be written as: $oExcel = ObjCreate("Excel.Application") ; Create an Excel Object WITH $oExcel .Visible = 1 ; Let Excel show itself .WorkBooks.Add ; Add a new workbook .ActiveWorkBook.ActiveSheet.Cells(1,1).Value="test" ; Fill a cell sleep(4000) ;See the results for 4 seconds .ActiveWorkBook.Saved = 1 ; Simulate a save of the Workbook .Quit ; Quit Excel ENDWITH This example does not save you a lot of text, but when your object uses long lines of properties/methods, you can shorten it heavily within a WITH statement. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 3, 2010 Share Posted June 3, 2010 Well, PHP allows you to do things like that because the entire language is dynamic. While AutoIt types are dynamic, the language structure itself is not. Link to comment Share on other sites More sharing options...
daluu Posted June 3, 2010 Share Posted June 3, 2010 Well, since AutoIt is very identical to VBScript, the solution to both may be similar. In VBScript, response."711".name is likely invalid as well. Typically, I think one would reference that more like something like this: response.item("711").name response.node("711").name The only problem here is figuring out the property collection name to use to specify the node/property "711" of interest (e.g. is it item, node, or something else?). Since we are talking about XML-RPC and specific library being used, I wouldn't know the proper reference method. In terms of XML, one can look up how to access the desired node "711" for example by following the XML DOM reference. I assume it is similar for XML-RPC since it uses XML. One reference site for that would be http://www.w3schools.com/dom/dom_node.asp, there are other sites as well. 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