{"id":1842,"date":"2008-08-30T13:03:50","date_gmt":"2008-08-30T13:03:50","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/?p=1842"},"modified":"2008-08-30T13:04:29","modified_gmt":"2008-08-30T13:04:29","slug":"popup-window-preventing-pile-ups","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2008\/08\/30\/popup-window-preventing-pile-ups\/","title":{"rendered":"Popup Window: Preventing pile-ups"},"content":{"rendered":"

By Dennis Brown<\/p>\n

The popup window is a great tool in debugging and can help you to keep track of what your code is doing or it can be used to alert you to special situations in your normally running formula. A common problem is that if you call PopupWindow() from a loop or if one gets generated on every AFL pass, you can get hundreds or even thousands of pop-ups piling up on your screen. Tomasz posted a simple work-around on the AmiBroker Feedback Center that took care of the problem in some cases (Suggestion 1528<\/a>):<\/p>\n

The following is a more complete version of this solution that adds a popupID to keep track of each individual popup window and re-enable the popup after its specified timeout period, or if any of the displayed text changes:<\/p>\n

<\/span>function <\/span>GetSecondNum<\/span>()\r{\r    <\/span>Time <\/span>= <\/span>Now<\/span>( <\/span>4 <\/span>);\r    <\/span>Seconds <\/span>= <\/span>int<\/span>( <\/span>Time <\/span>% <\/span>100 <\/span>);\r    <\/span>Minutes <\/span>= <\/span>int<\/span>( <\/span>Time <\/span>\/ <\/span>100 <\/span>% <\/span>100 <\/span>);\r    <\/span>Hours <\/span>= <\/span>int<\/span>( <\/span>Time <\/span>\/ <\/span>10000 <\/span>% <\/span>100 <\/span>);\r    <\/span>SecondNum <\/span>= <\/span>int<\/span>( <\/span>Hours <\/span>* <\/span>60 <\/span>* <\/span>60 <\/span>+ <\/span>Minutes <\/span>* <\/span>60 <\/span>+ <\/span>Seconds <\/span>);\r    return <\/span>SecondNum<\/span>;\r}\r\rfunction <\/span>PopupWindowEx<\/span>( <\/span>popupID<\/span>, <\/span>bodytext<\/span>, <\/span>captiontext<\/span>, <\/span>timeout<\/span>, <\/span>left<\/span>, <\/span>top <\/span>)\r{\r    <\/span>displayText <\/span>= <\/span>bodytext <\/span>+ <\/span>captiontext<\/span>;\r    if ( ( <\/span>StaticVarGetText<\/span>( <\/span>"prevPopup" <\/span>+ <\/span>popupID <\/span>) != <\/span>displayText<\/span>) OR ( <\/span>StaticVarGet<\/span>( <\/span>"prevPopupTime" <\/span>+ <\/span>popupID <\/span>) < <\/span>GetSecondNum<\/span>() ) )\r    {\r        <\/span>StaticVarSetText<\/span>( <\/span>"prevPopup" <\/span>+ <\/span>popupID<\/span>, <\/span>displayText<\/span>);\r        <\/span>StaticVarSet<\/span>( <\/span>"prevPopupTime" <\/span>+ <\/span>popupID<\/span>, <\/span>GetSecondNum<\/span>() + <\/span>timeout <\/span>);\r        <\/span>PopupWindow<\/span>( <\/span>bodytext<\/span>, <\/span>Captiontext <\/span>+ <\/span>popupID<\/span>, <\/span>timeout<\/span>, <\/span>Left<\/span>, <\/span>top <\/span>);\r    }\r}\r\r<\/span>PopupWindowEx<\/span>( <\/span>"ID:1"<\/span>, <\/span>"testing"<\/span>, <\/span>"test alert "<\/span>, <\/span>5<\/span>, -<\/span>1<\/span>, -<\/span>1 <\/span>);\r<\/span>PopupWindowEx<\/span>( <\/span>"ID:2"<\/span>, <\/span>"testing"<\/span>, <\/span>"test alert "<\/span>, <\/span>5<\/span>, <\/span>0<\/span>, <\/span>0 <\/span>);<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"

By Dennis Brown The popup window is a great tool in debugging and can help you to keep track of what your code is doing or it can be used to alert you to special situations in your normally running formula. A common problem is that if you call PopupWindow() from a loop or if […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[78,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1842"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=1842"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1842\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=1842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=1842"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=1842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}