olmanRvr Posted January 22, 2016 Share Posted January 22, 2016 #RequireAdm AutoItSetOption("WinTitleMatchMode",2) Func makeOdrs() Local $AD=0.05 Local $PRICE=ControlGetText("try - DP0280","NSE",2639) Local Static $st=True Local $margin=9 If $st= True Then $st=False Local $QTY= 3000/$PRICE*$margin; $margin already defined $QTY = Round($QTY) ControlSetText("try - DP0280","NSE",2640,$QTY);qty Local $wTITLE=WinGetTitle("try - DP0280","NSE") If $wTITLE= "Sell Order Entry - DP0280" Then $AD *= -1; to substract $AD from $PRICE if ‘sell order’ EndIf $PRICE += $AD ControlSetText("try - DP0280","NSE",2802,$PRICE);trigger $PRICE += $AD ControlSetText("try - DP0280","NSE",2639,$PRICE);price Else Local $wTITLE=WinGetTitle("try - DP0280","NSE") If $wTITLE= "Sell Order Entry - DP0280" Then $AD *=-1 EndIf ControlSetText("try - DP0280","NSE",2802,$PRICE);trigger $PRICE += $AD ControlSetText("try - DP0280","NSE",2639,$PRICE);price EndIf EndFunc Hello Everybody, I just joined the forum.I am new to scripting .This my first post. A belated Happy New Year to all. i am trying to write a function where i want a variable($QTY) to be assigned only in the first call.Using $st as static variable to do so.But still the $QTY changes value on subsequent calls.Can any one please help me.The code is as above. cheers & thanks olmanR Link to comment Share on other sites More sharing options...
water Posted January 22, 2016 Share Posted January 22, 2016 I do not see anything wrong with the posted part of your script. Can you insert ConsoleWrite($st & @CRLF) after Local Static $st=True so you can see if the value of $st is as expected. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
olmanRvr Posted January 22, 2016 Author Share Posted January 22, 2016 Hi Water, Thanks for your suggestion. After trying it I will get back cheers olmanR Link to comment Share on other sites More sharing options...
olmanRvr Posted January 23, 2016 Author Share Posted January 23, 2016 Hey Water, Yes I tried your suggestion, ConsoleWrite($st & @CRLF) Every time it returns True. But after the "$st=True Then" ,it was set to false. As I understand, as a static variable, $st should be false after the first call. Please correct my concept if wrong. And help thanks & cheers olmanR Link to comment Share on other sites More sharing options...
water Posted January 23, 2016 Share Posted January 23, 2016 Any chance that $st is modified somewhere else in your script? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
olmanRvr Posted January 23, 2016 Author Share Posted January 23, 2016 Hi, If initially assigned outside "if" or "while Wend" constructs , @consoleWrite shows true,false,false,false,false,false,.......But still $QTY changes on subsequent calls.I tried global static instead of local, with same result but an extra issue----> error:Cannot make existing variables static.:Pl have a look at the revised script. Also the func agnAgn() is looping only once. expandcollapse popup#RequireAdm AutoItSetOption("WinTitleMatchMode",2) agnAgn() ;makeOdrs() Func makeOdrs() Global Static $st="True" Local $AD=0.05 Local $wTITLE=WinGetTitle("try - DP0280","NSE") If $wTITLE= "Sell Order Entry - DP0280" Then $AD *= -1; to substract $AD from $PRICE if ‘sell order’.now is -0.05 EndIf Local $margin=9 Local $PRICE=ControlGetText("try - DP0280","NSE",2639) If $st= True Then $st=False Local $QTY= 3000/$PRICE*$margin $QTY = Round($QTY) ControlSetText("try - DP0280","NSE",2640,$QTY);qty $PRICE += $AD; trigger price ControlSetText("try - DP0280","NSE",2802,$PRICE); setting trigger $PRICE += $AD ;price ControlSetText("try - DP0280","NSE",2639,$PRICE);setting price Else $PRICE += $AD; trigger price ControlSetText("try - DP0280","NSE",2802,$PRICE); setting trigger $PRICE += $AD ;price ControlSetText("try - DP0280","NSE",2639,$PRICE);setting price EndIf EndFunc Func agnAgn() Local $x Local $i=0 for $x =0 To 10 makeOdrs() $i +=1 ConsoleWrite($x &@CRLF) Next EndFunc Link to comment Share on other sites More sharing options...
water Posted January 23, 2016 Share Posted January 23, 2016 $st is defined/used somewhere else in your script (what you posted is only a part of your script). A little reproducer to test: Global $test = True _Test() Func _Test() Global Static $test = False ConsoleWrite($test & @CRLF) EndFunc ;==>_Test returns: "Cannot make existing variables static." Remove line Global $test = True and you do not get the error. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
mikell Posted January 23, 2016 Share Posted January 23, 2016 Declaring "Global Static" is redundant and makes no sense... agnAgn() Func makeOdrs($n) Local Static $st = True If $st= True Then ConsoleWrite("$st=True" & ", makeOdrs=" & $n & @CRLF) $st=False Else ConsoleWrite("$st=False"& ", makeOdrs=" & $n & @CRLF) EndIf EndFunc Func agnAgn() for $x = 1 To 10 ConsoleWrite("for loop : " & $x &@CRLF) makeOdrs($x) Next EndFunc Link to comment Share on other sites More sharing options...
olmanRvr Posted January 23, 2016 Author Share Posted January 23, 2016 Hi Water & mikell, Thanks a lot to both of you.After removing that "Global Static" declaration as suggested, now the code is running smooth.I look forward to you all for possible issues in future . cheers olmanR Link to comment Share on other sites More sharing options...
water Posted January 23, 2016 Share Posted January 23, 2016 Still don't understand why the OPs original code didn't work. There is already a Local Static $st in his first post. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
mikell Posted January 23, 2016 Share Posted January 23, 2016 water, I agree... Link to comment Share on other sites More sharing options...
Developers Jos Posted January 23, 2016 Developers Share Posted January 23, 2016 (edited) Doesn't it make sense that the Quantity gets updated with each subsequent call as it is a Local variable defined each time in that first example? Jos Edited January 24, 2016 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
czardas Posted January 24, 2016 Share Posted January 24, 2016 (edited) 5 hours ago, water said: Still don't understand why the OPs original code didn't work. There is already a Local Static $st in his first post. The only explanation I can think of is that the function might only have been called once in the script. Subsequent runs call the function for the first time. Perhaps this is a matter of misinterpretation of the keyword Static, or a faulty debugging procedure (all variables get destroyed when a script terminates). I cannot reproduce the problem. Edited January 24, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 That's why I hate when users only post a few lines of code and tell us that the problem has to be there. I should more often insist on a stripped down reproducer script My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
mikell Posted January 24, 2016 Share Posted January 24, 2016 Yes, and also insist when solved on posting the final working code In this case it would be explanatory to see this 'running smooth' one czardas 1 Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 Me too. Posting the final solution to a problem is helpful for others users in the future. It's forum Netiquette. czardas 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
czardas Posted January 24, 2016 Share Posted January 24, 2016 1 hour ago, water said: Netiquette First time I heard this word! operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 It isn't used on the forum or wiki but you get details here: https://en.wikipedia.org/wiki/Etiquette_in_technology#Netiquette My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
olmanRvr Posted January 24, 2016 Author Share Posted January 24, 2016 `Hi Guys Sorry for the delayed post. Been working on my code, given below which is working fine. thanks for all the help & support cheers olmanR Func setQty() Static Local $sta =True if $sta=True Then $sta=False Local $SYM=ControlGetText("try - DP0280","NSE",2657) Local $prc=ControlGetText("try - DP0280","NSE",2639);price Local $magn=Call("getMarg","$SYM") Local $QTY=1000/$prc*$magn $QTY = Round($QTY) ControlSetText("try - DP0280","NSE",2640,$QTY);qty EndIf EndFunc Link to comment Share on other sites More sharing options...
water Posted January 24, 2016 Share Posted January 24, 2016 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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