none
Program flow in a SB program . What gets executed first ? RRS feed

  • Question

  • Hello & Thanks ;

    What is the progression of program flow in a SB program . 

    What gets executed first . Is it a flow from top to bottom ? 

    Do subroutines only get executed when called ?

    Thanks for your Help...


    "All things in moderation, except for love and forgiveness."...vm

    Thursday, August 6, 2020 9:07 PM

Answers

  • also event subs are very special kind of subs and can be source of many strange errors.

    in order to avoid them obey these

    rules for event-subs :

    • event subs must be very short
    • avoid long and complicated IFs
    • do not call other subs or lddialogs
    • do not use goto cmds to jump outside event sub
    • make main loop and inside loop exec desired event code:

    example:

    graphicswindow.keydown=kkk

    sub kkk

    if graphicswindow.lastkey="Space" then 'key space pressed

     evv="true

    endif

    endsub

    while 1=1 'repeat forever

       if evv then

         evv="false" 'anullate event

        'event code

      endif

    endwhile

    Friday, August 7, 2020 7:22 PM

All replies

  • Yes that is right. The only exception is the use of the (depreciated) use of GoTo.

    Jan [ WhTurner ] The Netherlands


    Friday, August 7, 2020 8:41 AM
    Answerer
  • Thanks ;

    What gets executed first . Is it a flow from top to bottom ? 

    Do subroutines only get executed when called ?

    Yes on both questions ?

    Thanks


    "All things in moderation, except for love and forgiveness."...vm

    Friday, August 7, 2020 6:01 PM
  • subs exec only on calls, no matther of positioning

    event subs must be placed only after callcmd

    e.g.

    GraphicsWindow.KeyDown=kkk

    sub kkk

    'do something w keys

    endsub

    Friday, August 7, 2020 6:47 PM
  • also event subs are very special kind of subs and can be source of many strange errors.

    in order to avoid them obey these

    rules for event-subs :

    • event subs must be very short
    • avoid long and complicated IFs
    • do not call other subs or lddialogs
    • do not use goto cmds to jump outside event sub
    • make main loop and inside loop exec desired event code:

    example:

    graphicswindow.keydown=kkk

    sub kkk

    if graphicswindow.lastkey="Space" then 'key space pressed

     evv="true

    endif

    endsub

    while 1=1 'repeat forever

       if evv then

         evv="false" 'anullate event

        'event code

      endif

    endwhile

    Friday, August 7, 2020 7:22 PM
  • Ah that's Great info 

    Thank you very much !


    "All things in moderation, except for love and forgiveness."...vm

    Friday, August 7, 2020 8:56 PM