Announcement

Collapse
No announcement yet.

Calling a function using a variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    I think there are two decisions made by PB a long time ago which in hindsight PB wishes it had made differently....

    1. Making #DIM NONE the default instead of #DIM ALL. Many less problems requring intervention by the PB support department if the users (that would be you and me) had to go out our way to allow 'undeclared variables'

    2. Using the syntax "THREAD CLOSE" instead of "THREAD CLOSE HANDLE". I think this might be the 'winner' in terms of people not understanding what this statement does (notwithstanding that it's clearly documented).
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #22
      Ok, thanks guys. In regard to program flow concepts for the converted app, I think ready to go.

      Now all that's left for me is some keystroke handling conversion issues (e.g. ON KEY(3)/KEY ON/KEY OFF equivalents), and issuing a RETURN to a specific line (e.g. "RETURN 1200", in QB returns to line 1200, which can't be done in PB). To keep things on topic, I'll address these in their own threads however.

      Comment


      • #23
        RETURN 1200 -->> substitute...

        ASM ADD ESP, 4
        GOTO 1200

        Comment


        • #24
          Wow, thanks very much! Wouldn't exactly have guessed that...

          Comment


          • #25
            Originally posted by Bob Zale View Post
            ASM ADD ESP, 4
            GOTO 1200
            That's handy... future proof?

            Comment


            • #26
              You have to love this BASIC: assembly language freely intermixed with GOTO.

              Something for everyone I guess.
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #27
                MCM,
                <<assembly language freely intermixed ..>>

                If PB didn't allow that I'd had gone elsewhere.

                Paul.

                Comment


                • #28
                  Originally posted by Chris Holbrook View Post
                  That's handy... future proof?

                  For 32-bit code... yes.

                  Comment


                  • #29
                    Looks like someone should be sending in a New Feature Suggestion...

                    " Please add support for "RETURN linenumber"

                    On second thought, don't do that. Trying to figure out code with lots of GOTOs is bad enough.

                    MCM
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #30
                      Close enough?

                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      
                       MACRO ReturnToLine (LineNumber)
                       ' This macro is a substitute for 'RETURN lLineNumber' as instructed by Bob Zale in this forum 2008-09-18
                         ! ADD ESP, 4
                         GOTO LineNumber
                       END MACRO
                      
                      FUNCTION PBMAIN () AS LONG
                      
                         LOCAL sKeys AS STRING
                      
                         GOSUB AB
                         PRINT "Will not display"
                      
                      
                      1200  PRINT "Will display"
                      
                         EXIT FUNCTION
                      
                      AB:
                         ReturnToLine (1200)
                      
                      END FUNCTION
                      Sorry - MSGBOX in the Console Compiler forum? MSGBox replaced with PRINT
                      Last edited by Vidar Hanto; 25 Sep 2008, 10:28 AM.

                      Comment


                      • #31
                        Could also do the same thing without assembly language by setting a user-defined error and RESUME linenumber.

                        ie

                        Code:
                        %MY_ERROR =   151   ' or whatever is in range 
                        
                        ON ERROR GOTO Handler 
                        
                           IF condition  
                               ERROR %MY_ERROR 
                        ...
                        ...
                        Where_To_Restart :
                             PRINT " restarted after condition was true here" 
                        ...
                        
                        Handler:
                             IF ERR = %My_ERROR THEN 
                               do something 
                               RESUME   Where_to_restart
                               ....
                        But IMO both this and "RETURN linenumber" are UGLY spaghetti code... way too many "jumps" for my taste.


                        MCM
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment

                        Working...
                        X