none
Need Help With A Loop! RRS feed

  • Question

  • In this program: DPT430

    I want the program to go back to the menu by pressing a button or key on one of the pages/miniapps/subs but it isnt working. Any help would be greatly apreciated!
    I have tried using a goto but it isnt going back I really dont know what to do.
    Tuesday, February 9, 2010 10:33 PM

Answers

  • Hi Mastercheese,

    The problem you are having is due to you mixing Goto's and Subs and Events, which is just confusing SmallBasic somewhat as you are mixing two different programming styles and forcing SmallBasic to jump out of an Event before it fully completes. 

    Either stick to just using Goto's, or change your program to only use Sub's and Events.

    Although the recommended route is to use Sub's and Events, I've shuffled your program code around a bit so that it now *only* uses Goto's.  You can import it using this code: DPT430-0

    However, you will fairly quickly notice a bug.  This is due to the way that SmallBasic handles the .LastKey value, in that it *never* forgets what the last key was, so once you've pressed Return once to get back to the menu, it remembers this for ever (or until a different key is pressed) so the program always returns back to the menu immediately after showing menu1.  Try uncommenting the 'Goto waitMouse command on line 103 for an alternative method, which waits for a mouse click before returning to the main menu rather than a keypress.

    There's a good answer from Vijaye about lastkey and events over on this thread.

    PS.  Oops, I forgot to delete line 45 before publishing it.
    • Marked as answer by Mastercheese Wednesday, February 10, 2010 1:30 AM
    Wednesday, February 10, 2010 12:53 AM

All replies

  • Hi Mastercheese,

    The problem you are having is due to you mixing Goto's and Subs and Events, which is just confusing SmallBasic somewhat as you are mixing two different programming styles and forcing SmallBasic to jump out of an Event before it fully completes. 

    Either stick to just using Goto's, or change your program to only use Sub's and Events.

    Although the recommended route is to use Sub's and Events, I've shuffled your program code around a bit so that it now *only* uses Goto's.  You can import it using this code: DPT430-0

    However, you will fairly quickly notice a bug.  This is due to the way that SmallBasic handles the .LastKey value, in that it *never* forgets what the last key was, so once you've pressed Return once to get back to the menu, it remembers this for ever (or until a different key is pressed) so the program always returns back to the menu immediately after showing menu1.  Try uncommenting the 'Goto waitMouse command on line 103 for an alternative method, which waits for a mouse click before returning to the main menu rather than a keypress.

    There's a good answer from Vijaye about lastkey and events over on this thread.

    PS.  Oops, I forgot to delete line 45 before publishing it.
    • Marked as answer by Mastercheese Wednesday, February 10, 2010 1:30 AM
    Wednesday, February 10, 2010 12:53 AM
  • Thank you so much! I can't thank you enough Davey-Wavey! You solved my problem perfectly! Right after I posted this I started switching my program to subs/events. I just was looking for the right command which you showed me. Once again, thank you!
    Wednesday, February 10, 2010 1:30 AM