Zohar Posted June 10, 2010 Share Posted June 10, 2010 (edited) Hello I have a webpage, where I find a TextBox object, and then Set value to it. I use a small function that I wrote to find the Object, and then I set the innerText value of it. It's something like this: Local $PO_Name =SomeFunction() ;This function Finds the Object in the webpage, and returns it $PO_Name.innerText="Abc Def" If I try to write these 2 lines as 1 line, like this: SomeFunction().innerText="Abc Def" then it doesn't even compile.. It says "ERROR: syntax error" Is there any way I can make those 2 lines be 1? that way I also save myself the need to define a variable for it. Thank you Edited June 17, 2010 by Zohar Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 10, 2010 Moderators Share Posted June 10, 2010 Your question is confusing at best. Global $oPO_Name = _SomeFunc("Abc Def") Func _SomeFunc($s_innertext = "") ; Do whatever you normally do Local $o_po_name = "however you got our object that you returned originall" If IsObj($o_po_name) And $s_innertext Then $o_po_name.innerText = $s_innertext EndIf Return $o_po_name EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Zohar Posted June 10, 2010 Author Share Posted June 10, 2010 (edited) Hi smoke-n!!Thank you very much for your reply.What you did, definately made it 1 line,but my question is different.Assume for example that you cannot touch the Function and can only use it as is.My problem then, is how can I write "SomeFunction()", and then immediately after it add ".Property=value",like:SomeFunction().innerText="Abc Def"AutoIt syntax checking tool simply won't let me.Is there anything that can be done so it will be possible?Or is it a feature that I should hope that will be added in the future? Edited June 10, 2010 by Zohar Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 10, 2010 Moderators Share Posted June 10, 2010 Hi smoke-n!!Thank you very much for your reply.What you did, definately made it 1 line,but my question is different.Assume for example that you cannot touch the Function and can only use it as is.My problem then, is how can I write "SomeFunction()", and then immediately after it add ".Property=value",like:SomeFunction().innerText="Abc Def"AutoIt syntax checking tool simply won't let me.Even if the syntax checking tool allowed it, and you compiled, You'd get an interpreter error like:Error:Illegal text at the end of statement (one statement per line). As soon as you got to the 2nd part of the call. The initial function would fire. but the .innerText() would throw the exception error.Is there anything that can be done so it will be possible?Other than digging into these guys thread http://www.autoitscript.com/forum/index.php?showtopic=110379, hoping for a possible solution, I doubt it.Or is it a feature that I should hope that will be added in the future?I'm not sure on your wish list relevance really. I can't imagine creating this kind of change for fun in the autoit source when the user/coder can simply make a var to contain.Maybe you could explain the benefit? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Zohar Posted June 14, 2010 Author Share Posted June 14, 2010 well,it's not for fun at all.The reason why it can be useful, is because many times I create a function that returns an object,and then I need to use that object only 1 time, such as setting a property of it(e.g.: .innerText="aaaa"), or running a method of it(e.g.: .click()).Defining a variable for it, for just 1 time, is not needed.That's why I was hoping it's possible.. Link to comment Share on other sites More sharing options...
Tvern Posted June 14, 2010 Share Posted June 14, 2010 For that reason I usually have variables like $sTemp, $aTemp, or $oTemp. For instance if I use multiple stringregex' to get adress information I'll have one to return the streetname to $aTemp, and then write $aTemp[0] to $sStreet, after which I'll have one to write the city name to $aTemp and write $aTemp[0] to $sCity. This way you avoid creatign loads of variables that you hardly use, but if used improperly it can lead to confusing behavior if you don't empty the vars after using them. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 14, 2010 Moderators Share Posted June 14, 2010 Sounds like a feature request, not necessarily a benefit one. I suppose if you really needed something specific, you could create a personal standard property/method udf if you didn't want to play with the link I gave you. Something like this:_InnerText(_MyFuncThatCreatesTheOneTimeObject(), "myinnertext") Func _InnerText($o_obj, $s_text) If Not IsObj($o_obj) Then Return SetError(1, 0, 0) $o_obj.innerText($s_text) Return EndFunc Func _MyFuncThatCreatesTheOneTimeObject() Local $o_obj; = blah blahblah Return $o_obj EndFunc Would leave it at one line, and having the udf, would allow you to use the function calls over and over in other scripts. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Zohar Posted June 14, 2010 Author Share Posted June 14, 2010 hi smoke-n =] your solution is nice, but it only works if the person only needs the same property everytime: ".innerText". But as you know, this is not the case. and of course, we can make a work around for that too: we can add a parameter to the function, that will get the Property name, and then inside the function will be a switch.. but it would be much simpler to have the language enable it and it would work every time, with every property/method, and not just ones that our function was already programmed for in advance. Link to comment Share on other sites More sharing options...
Authenticity Posted June 14, 2010 Share Posted June 14, 2010 It is called Method Chaining and it has something to do with object oriented language. Doing so with an OOL is just fine because such a language is strong-type language, i.e the compiler or RTTI are able to determine the method to invoke from the returning object. AutoIt does not implement such a feature, but who knows; things tend to happen. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 14, 2010 Moderators Share Posted June 14, 2010 but who knows; things tend to happen. Amen Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Zohar Posted June 14, 2010 Author Share Posted June 14, 2010 (edited) ok.. Edited June 14, 2010 by Zohar 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