LB Booster
« pressing ESC aborts the program »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:34am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: pressing ESC aborts the program  (Read 1521 times)
metro
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx pressing ESC aborts the program
« Thread started on: Sep 13th, 2016, 09:31am »

in need of assistance,
my first post, after downloading LBB today I decided to load up a LB 4.5*.bas program I have put together to download option quotes from the Australian Stock Market web site (ASX) . It works fine in LB!
I have altered some code that prevented me from running it from the LBB IDE (namely HTTPGET$ to httpget$ and others),

But I have a mystery I can solve.

If I press the keyboard's "ESC" key once the program has loaded the program aborts with no further warning, (the IDE is still running though)
however if I make a selection from one of the list boxes I do not have the issue.
the same problem exists after compiling too.
any ideas??
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #1 on: Sep 13th, 2016, 11:03am »

on Sep 13th, 2016, 09:31am, metro wrote:
If I press the keyboard's "ESC" key once the program has loaded the program aborts with no further warning

The Esc key should work as it normally does in Windows, that is in a DIALOG type window pressing Esc should behave the same as clicking on the Close box, but otherwise it should be ignored. For example try this program:

Code:
    open "Test" for dialog as #w
    #w "trapclose quit"
    wait

sub quit h$
    print "Close was clicked or Esc pressed"
end sub 

If you think something different is happening please list a (preferably short) program which demonstrates the issue.

Richard.
User IP Logged

metro
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: pressing ESC aborts the program
« Reply #2 on: Sep 13th, 2016, 1:25pm »

Quote:
(preferably short)

Sorry Richard its not short, I have taken the code up to the first WAIT
and rem'd out lines that would stop it running.
It is still work in progress however as stated before I have no issues in LB4.5
just an aside, I cant believe how much faster it runs using LBB.
if you simply press "Esc" when the program opens it will immediately close

I can make the whole program available through dropbox if that helps
however there is a SQLite DB so the whole thing in 1.6mb

Code:
  nomainwin
    'Form created with the help of Freeform 3 v07-15-08
    'Generated on Nov 17, 2015 at 17:02:38

    sep$       =chr$(34)+chr$(44)+chr$(34)   :Blank$=Chr$(34)+"C"+Chr$(34) :Str1$ =")"+chr$(34)+">"
    MyEol$     =chr$(44)+chr$(34)+chr$(34)   :DDQ$  =Chr$(34)+Chr$(34)
    ControlDir$=DefaultDir$+"\CTRL\"
    DataDir$   =DefaultDir$+"\DAT\"

    GLOBAL AsxCode$ , Dquote$,Str1$
    GLOBAL OptType$ ,TransType$

[setup.main.Window]

  '  loadbmp "BannerImage", ControlDir$+"financeBanner.bmp"

    '-----Begin code for #buy



    MainWinWidth = 800
    MainWinHeight = 600

    WindowWidth = MainWinWidth
    WindowHeight = MainWinHeight
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)


    '-----Begin GUI objects coderecord
    graphicbox   #buy.GbLine3,   3,   1, 785,  3
    graphicbox   #buy.GbBanner,   3,   5, 785,  60
    graphicbox   #buy.GbLine1,   3,   66, 785,  3

    TextboxColor$ = "white"

    statictext  #buy.StPFolio,"Portfolio"    ,       20,  75,  65,  20
    combobox    #buy.CbPFolio, PFolio$(), [SelPFolio],  10,  95, 150,  25

    statictext  #buy.StBroker,"Broker"    ,           190,  75,  65,  20
    combobox    #buy.CbBroker, Brokers$(), [SelBroker],  175,  95, 100,  25

    statictext  #buy.StOpenDate, "Open Date",  20,  125,  65,  20
    textbox     #buy.TbOpenDate,                  10,  145, 100,  25

    statictext  #buy.StOptCode, "Opt Code",  140, 125,  57,  20
    textbox     #buy.TbOptCode,              120, 145, 100,  25
    Stylebits   #buy.TbOptCode, _ES_UPPERCASE, 0, 0, 0

    button      #buy.Btnfind  , "FIND", [SEARCH4CODE], UL, 235, 145

    statictext  #buy.StStyle  , "Style",  20, 175,  57,  20
    textbox     #buy.TbStyle  ,           10, 195, 100,  25
    Stylebits   #buy.TbStyle, _ES_CENTER OR _ES_UPPERCASE,0, 0, 0

    statictext  #buy.StStrike, "Strike", 150, 175,  34,  20
    textbox     #buy.TbStrike,           120, 195, 100,  25
    Stylebits   #buy.TbStrike, _ES_RIGHT, 0, 0, 0

    statictext  #buy.StExpDate, "Expire Date", 250, 175,  70,  20
    textbox     #buy.TbExpDate,                  230, 195, 100,  25
    Stylebits   #buy.TbExpDate, _ES_RIGHT, 0, 0, 0

    statictext  #buy.StType, "Type", 345, 175,  32,  20
    textbox     #buy.TbType,         340, 195,  50,  25
    Stylebits   #buy.TbType, _ES_CENTER OR _ES_UPPERCASE,0, 0, 0

    statictext  #buy.StSharesPerCon, "Shares/ Contract", 405, 175, 118,  20
    textbox     #buy.TbSharesPerCon,                  405, 195, 100,  25
    Stylebits   #buy.TbSharesPerCon, _ES_RIGHT, 0, 0, 0

    radiobutton #buy.RbBUY, "BUY", [CALCTOTAL], dummy,525,175,60,20
    radiobutton  #buy.RbSELL, "SELL", [CALCTOTAL],dummy,525,205,60,20

    statictext  #buy.StNumCont, "Num Contracts", 125, 220,  87,  20
    textbox     #buy.TbNumCont,                  120 ,240, 100,  25
    Stylebits   #buy.TbNumCont, _ES_NUMBER, 0, 0, 0
    Stylebits   #buy.TbNumCont, _ES_RIGHT, 0, 0, 0

    statictext  #buy.StOpenBro, "Brokerage", 243, 220,  87,  20
    textbox     #buy.TbOpenBro,                  230 ,240, 100,  25
    Stylebits   #buy.TbOpenBro, _ES_RIGHT, 0, 0, 0
    'Stylebits  #buy.TbOpenBro, _ES_NUMBER, 0, 0, 0

 statictext  #buy.StFees, "Fees", 350, 220,  87,  20
    textbox     #buy.TbOpenFee,   340 ,240, 50,  25
    Stylebits   #buy.TbOpenFee, _ES_RIGHT, 0, 0, 0
    'Stylebits  #buy.TbOpenFee, _ES_NUMBER, 0, 0, 0

    button      #buy.BtnCalc, " CALCULATE ", [CALCTOTAL], UL, 405, 240

    statictext  #buy.statictext51, "NOTES", 170, 280, 250,  40
    TexteditorColor$ = "white"
    texteditor  #buy.textedit42,  20, 320, 450, 200
    ComboboxColor$ = "white"

    statictext #buy.StOpenPrice, "Open Price",  20, 220,  67,  20
    textbox    #buy.TbOpenPrice,                10, 240, 100,  25
    Stylebits  #buy.TbOpenPrice, _ES_RIGHT, 0, 0, 0
    button     #buy.BtnStore, " RECORD ", [SAVERECORD], UL, 530, 240
    button     #buy.BtnChart, " CHART ", [DISPLAYCHART], UL, 620, 240

    statictext #buy.StTradeNum, "Trade Number", 520,  83,  128,  20
    textbox    #buy.TbNumber,                   660,  77,   80,  33

    stylebits  #buy.TbNumber,  0,_WS_BORDER, 0, _WS_EX_CLIENTEDGE
    Stylebits  #buy.TbNumber,    _ES_CENTER,0, 0, 0
    Stylebits  #buy.TbNumber,    _ES_READONLY, 0, 0, 0
    Stylebits  #buy.TbNumber,  0,_WS_TABSTOP, 0, 0

    statictext #buy.StMessage1, "DataBase Last Updated...",  20, 525,  265,  20
    textbox    #buy.TbGrossPrem,      620, 320, 100,  25
    statictext #buy.stGross, "Gross", 540, 320,  64,  20
    Stylebits  #buy.TbGrossPrem,_ES_RIGHT OR_ES_READONLY,0,0,0

    textbox    #buy.TbTotalBro,              620, 355, 100,  25
    statictext #buy.StBrokerage, "Brokerage",540, 355,  64,  20
    Stylebits  #buy.TbTotalBro,_ES_RIGHT OR_ES_READONLY,0,0,0

    textbox    #buy.TbOpenFees,     620, 385, 100,  25
    statictext #buy.StFees, "Fees", 540, 385,  31,  20
    Stylebits  #buy.TbOpenFees,_ES_RIGHT OR_ES_READONLY,0,0,0

    textbox    #buy.TbNetAmount      , 620, 415, 100,  25
    statictext #buy.NetAmount, "NET",  540, 415, 50,  20
    Stylebits  #buy.TbNetAmount,_ES_RIGHT OR_ES_READONLY,0,0,0

    graphicbox #buy.GbLine,            10,274, 775,  3

    '-----End GUI objects code

    '-----Begin menu code
    menu #buy, "Edit"  ' <-- Texteditor menu.
    menu #buy,  "&Tools","D_LoadMasterList",[DOWNLOADMATSERLIST],"UpDate Opt Data",[LOADDATA], "Delete Old Dates", [CLEANDB]
    '-----End menu code

    open "OPEN TRADE" for window as #buy
     #buy.BtnStore,"!disable"
     #buy.GbBanner, "down"
     #buy.GbBanner, "drawbmp BannerImage 0 0 ;flush"
     #buy.GbLine," down; fill darkgreen; flush"
     #buy.GbLine1," down; fill darkgreen; flush"
     #buy.GbLine3," down; fill darkgreen; flush"
     #buy, "font ms_sans_serif 10"
     #buy.statictext51, "!font Times_New_Roman Bold 20"
     #buy.RbBUY,"SET" : TransType$="B"
     #buy, "trapclose [quit.main]"

     #buy.StTradeNum, "!font Times_New_Roman Bold 15"
     #buy.TbNumber, "!font Times_New_Roman Bold 20";

[main.inputLoop]
 '   gosub [OPENDLL]
  '  gosub [OPENDB]
 '   gosub [LOADCONTROLFILE]
 '   gosub [SETVARIABLES]
 '   gosub [GETNEXTTRADENUMBER]
'    gosub [UPDATETRADENUMBER] 'need to move to after record save
  
'   gosub [LOADLASTUPDATE]
   #buy.StMessage1, "DataBase Last Updated..."+ LastUpdate$
  #buy.TbOptCode,"!Setfocus"
wait

[quit.main] 'End the program
    close #buy
   ' close #sq3
  '  unloadbmp("BannerImage")

END
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #3 on: Sep 13th, 2016, 1:45pm »

on Sep 13th, 2016, 1:25pm, metro wrote:
if you simply press "Esc" when the program opens it will immediately close

Because your window contains controls it's behaving like a dialog and Esc is being treated exactly like clicking on the Close button; you can confirm that by outputting a diagnostic message in the [quit.main] branch.

Since that is standard behavior for a Windows dialog box I'm rather surprised it's not what you want, but if it's essential that Esc doesn't act the same as Close you can test for it in the trapclose handler as follows:

Code:
[quit.main] 'End the program on Close, ignore Esc
    calldll #user32, "GetAsyncKeyState", _VK_ESCAPE as long, ret as short
    if ret < 0 then wait
    close #buy 

Because of the asynchronous nature of testing the key I can't guarantee that this will be 100% successful, but it seems to be pretty reliable here. Is it an acceptable workaround from your point of view?

Richard.
User IP Logged

metro
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: pressing ESC aborts the program
« Reply #4 on: Sep 13th, 2016, 2:06pm »

Thanks Richard
The work around may be fine, I am showing my limited understanding here of window types.
How is it that clicking on either of the two combo boxes stops the window from acting as a dialog.
That is ESC no longer closes the program.
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Re: pressing ESC aborts the program
« Reply #5 on: Sep 13th, 2016, 3:46pm »

If you rem the line:

#buy.TbOptCode,"!Setfocus"

just before the 'wait' statement, then esc doesn't close the program, but I don't know why. I don't think any control is causing your 'window' to act like a 'dialog'.
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Re: pressing ESC aborts the program
« Reply #6 on: Sep 13th, 2016, 4:04pm »

If you run this minimal program, esc will quit.

Code:
NoMainWin
WindowWidth = 800 : WindowHeight = 600
textbox #win.textbox1, 260, 140, 100, 25
open "Esc Test" for window as #win
#win "TrapClose [quit]"
wait
[quit]
close #win
end
 


If a text box has focus then esc will quit. It doesn't seem right to me.
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: pressing ESC aborts the program
« Reply #7 on: Sep 13th, 2016, 6:51pm »

Quote:
that Esc is the standard keyboard shortcut for Cancel/Close in a Windows dialog box,


yes but why close window of type "window"?
User IP Logged

metro
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: pressing ESC aborts the program
« Reply #8 on: Sep 13th, 2016, 7:05pm »

Quote:
yes but why close window of type "window"?

That was to be my next question
don't read anything into this other that whats being said (its not a criticism)
the same behaviour is not experienced in LB4.5

User IP Logged

metro
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: pressing ESC aborts the program
« Reply #9 on: Sep 13th, 2016, 11:27pm »

Thanks for the reply Richard,
forget the compatibility issue I see this as a trap for new users, I see it as essential that any program written for LBB must set focus to any control other that a textbox for it to remain persistent on the screen for the end user.

Because as it stands now if I start a LBB program and press escape when it first loads up the program will terminate.

I just ran Jack Kelly's remember-it and pressed escape and it terminated.
I don't have any other main stream programs that I use behave that way, so QuickBooks Firefox ThunderBird and the list goes on, all must set focus to something other that a textbox when they first start.

I will now test a few more code snippets on this forum to see if it was just bad luck I chose Remember-it and we have the same issue.

I would be happy to accept loosing LB compatibility as there are many more features being built into your product, the speed and a single exe are appealing enough.
User IP Logged

Jack Kelly
Full Member
ImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 106
xx Re: pressing ESC aborts the program
« Reply #10 on: Sep 14th, 2016, 07:30am »

Remember-It uses dialog windows exclusively, precisely so users CAN use the esc key to exit a window or close the program. I prefer that option to be available and for that reason use dialog windows as much as possible.

If quitting a program could have disastrous consequences for the user, the programmer should use a 'confirm' pop-up with the text "Quit? Are you sure??" or something to that effect.

I agree with Richard. This is a minor issue not worthy of any more attention.
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: pressing ESC aborts the program
« Reply #11 on: Sep 14th, 2016, 07:38am »

Quote:
and nobody has ever commented on it before.

Lol wink
So it's so rare occasion noone ever pressed ESC before (or never figured out what happened then they did - I'd probably not).
But now you have a few people thinking it wrong. Consider it a request?

As for me, I was really surprised then I found that ESC closes dialog window in JB/LB - I believe it is not written in a helpfile anythere.
So I probably filed it as a bug. But then I was told "But this is normal for dialog window" - ok I accept it. After all in my mind dialog window is short-lived, opened for specific task and closed with OK or Cancel. So ESC just doubles Cancel button, looks reasonable.

But if I want to use this functionality I would create window of type "Dialog", right?
Just as Jack just wrote: Quote:
and for that reason use dialog windows


But main program window silently closing on ESC - not the thing I ever wanted.
(besides it works different depending on control with focus. Textbox having focus closes on ESC, button or window - no)

Quote:
You make it sound as though it was a deliberate decision,
You really think too good of my English. It was just "why". You explained that "why" pretty comprehensive (I dunno - lack of word - but I understand what you mean), but I still think this behaviour better be changed if possible.
« Last Edit: Sep 14th, 2016, 07:39am by tsh73 » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #12 on: Sep 14th, 2016, 08:17am »

on Sep 14th, 2016, 07:38am, tsh73 wrote:
besides it works different depending on control with focus. Textbox having focus closes on ESC, button or window - no

You should ask Microsoft about that one! It's always been the case in Windows that if a key has a 'shortcut action' in a specific control, then that's what it does. If a different control has focus then that same key may do something completely different, including closing the entire window.

Take the simple case of the Tab key. Normally in a dialog box Tab moves focus from one control to another, but if the focus is currently on an edit control Tab does something entirely different. Users are expected to be aware of which control currently has the focus and understand that various keys will behave differently as a result.

Quote:
But now you have a few people thinking it wrong. Consider it a request?

As far as adding it to the 'wishlist' is concerned I'll do a deal with you! I have not the slightest idea how I would modify LBB to prevent Esc closing the window, because I don't know how it happens. If you can find out, and tell me, how the keypress gets 'propagated' from the child control to its parent - i.e. what message(s) are sent and when - then I'll consider making a change. OK?

Richard.
« Last Edit: Sep 14th, 2016, 08:19am by Richard Russell » User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: pressing ESC aborts the program
« Reply #13 on: Sep 14th, 2016, 08:52am »

Quote:
As far as adding it to the 'wishlist' is concerned I'll do a deal with you! I have not the slightest idea how I would modify LBB to prevent Esc closing the window, because I don't know how it happens. If you can find out, and tell me, how the keypress gets 'propagated' from the child control to its parent - i.e. what message(s) are sent and when - then I'll consider making a change. OK?

Fair enough. I have no idea either but some reading on Windows API would not make me any harm wink
User IP Logged

metro
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: pressing ESC aborts the program
« Reply #14 on: Sep 14th, 2016, 10:33am »

Quote:
Remember-It uses dialog windows exclusively, precisely so users CAN use the esc key to exit a window or close the program. I prefer that option to be available and for that reason use dialog windows as much as possible.

my apology I should have checked that first

Well that was a rather robust debate, I will concede even if I had another life time I could not reach the level of expertise you all have.

I do find it bizarre that LB Booster and BBC Basic handle the Esc key in this manner. (read I have a limited understanding)

So today I tried FreeBasic , RealBasic and Free Pascal and they all perform the same as LB and JB, that said I can learn to live with the difference.

I will try Richards work around for now
Code:
[quit.main] 'End the program on Close, ignore Esc
    calldll #user32, "GetAsyncKeyState", _VK_ESCAPE as long, ret as short
    if ret < 0 then wait
    close #buy  


Quote:
I just don't get why you see 'closing on pressing Esc' as a "trap". Why is the 'new user' pressing the Esc key in the first place? People don't press keys at random just for the heck of it. grin


I know for a fact there is at least one user that will inadvertently press Esc twice when closing a Dialog, then what a shock your program has disappeared.
« Last Edit: Sep 14th, 2016, 11:03am by metro » User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls