Announcement

Collapse
No announcement yet.

PBDOS refresher - declaring variables?

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

  • PBDOS refresher - declaring variables?

    As I'm examining old PBDOS 3.5 code, I'm wondering about declaring variables.

    Now that I've programmed PBWIN and PBCC for so long, I find it so odd to see SUBs and FUNCTIONs that do NOT have a LOCAL statement (with variable names) near the routine's beginning...

    It looks like you could just start using a new variable and PBDOS would accept it (no need for LOCAL statements).

    Is that correct?

    Thanks,
    -John


    (I'm also having headaches with SHARED statements... which, for a short one-module program, I think could just be changed to GLOBALs...)



  • #2
    Any variable not explicitly declared is LOCAL.

    But no PB compiler - PB/DOS, PB/Windows or PB/CC - has ever required variable declaration unless using the #DIM ALL directive... which use I ALWAYS recommend.

    (I'm also having headaches with SHARED statements... which, for a short one-module program, I think could just be changed to GLOBALs...)
    GLOBAL was not available in PB/DOS. You had to use SHARED which is functionally identical.

    When you get into multiple-module PB/DOS applications, you'll have to brush up on using COMMON statements.

    Are you writing in PB/DOS (which I infer from your choice of forums in which you are asking)?

    Or are you looking to port code from MS-DOS/PB-DOS to Windows/PB for Windows?

    (I think you know what I think of mindless verb-for-verb, statement-for-statement ports of this nature).
    Michael Mattias
    Tal Systems Inc.
    Racine WI USA
    mmattias@talsystems.com
    http://www.talsystems.com

    Comment


    • #3
      Another handy tip: If you have a program using multiple files, put all your shared variables into one file. Name it anything you want but I used SHARED.BAS. Then $INCLUDE that file as the first line of in SUBS-n-FUNCTIONS. Comes in real handy if you have nested subs and functions and have to add variables. Just update your SHARED.BAS (one file) file and it's all there in one fell swoop.
      There are no atheists in a fox hole or the morning of a math test.
      If my flag offends you, I'll help you pack.

      Comment


      • #4
        Michael,
        1. "But no PB compiler - PB/DOS, PB/Windows or PB/CC - has ever required variable declaration unless using the #DIM ALL directive..."
        Wow, that speaks volumes about good habits I'd forgotten I had to acquire! I've been using #DIM ALL for so long, I'd forgotten what is allowed when you don't use it!

        2. Yes, I'm looking to translate an old PBDOS program to PBCC. As I'm re-learning the quirks of PBDOS (vs PBCC/PBWIN), I'm also looking at "what the heck did I do THAT for?" and trying to determine whether I can easily get a PBCC compilation, or if I have to start over from (almost) scratch.

        Mel,
        Thanks for that idea. This is a 1200-line, single file program, but I will keep your idea in mind if/as I break it up.

        Thanks,
        -John

        Comment


        • #5
          Hi John,

          If you declare in the beginning DEFINT A-Z, for example, you do not need any other declaration, even in SUBs or FUBCTIONs - you need only to append the type identifier to the other variables that are not integers. Arrays must always be properly dimensioned.
          "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

          Comment


          • #6
            I've said many times here I think #DIM ALL should have been the default and you'd have to "do something" to disable it.. which you'd think would at least make you think!

            It's just too darned easy to mistype a variable name only to find when the argument equals zero or <null string> the statement or function don't work so good.


            .
            Michael Mattias
            Tal Systems Inc.
            Racine WI USA
            mmattias@talsystems.com
            http://www.talsystems.com

            Comment


            • #7
              I'm also looking at "what the heck did I do THAT for?"
              Put me down for, "because that was the only way to do it {under MS-DOS|using PB/DOS}, that's why."

              Both the Windows' API and the compilers themselves offer so much more than they did before. Can you imagine NO 'ARRAY SORT?' How about no PB statement to get a filesize except to OPEN the file and query LOF()? (Ok, so you could get that using CALL INTERRUPT). How about drawing all images one pixel at a time?

              The good old days were not all good.

              Michael Mattias
              Tal Systems Inc.
              Racine WI USA
              mmattias@talsystems.com
              http://www.talsystems.com

              Comment


              • #8
                I'm still trying to figure out why I chose to use FLEX strings. I'm not so sure that using them was "the only way"... Maybe I was trying to learn their limitations?

                Frustrating that I should have created for myself back then a mystery that I would have to solve now.

                But I digress (besides, I started a separate thread yesterday for understanding my FLEX strings.)

                OK, off to dinner and a movie. This code thing is going to take a back seat for a few days.

                Thanks,
                -John

                Comment


                • #9
                  ...why I chose to use FLEX strings. I'm not so sure that using them was "the only way"..
                  I'm sure members would love to suggest other ways, except we are all totally clueless about WHAT you wish to accomplish, for which you chose to use flex strings when compiling for PB/DOS running under MS-DOS.

                  FWIW, if flex strings were the 'only way' (or even simply the lesser of evils), I think compiling for Windows using a PB for Windows compiler, FIELD variables almost certainly merit some consideration.

                  Michael Mattias
                  Tal Systems Inc.
                  Racine WI USA
                  mmattias@talsystems.com
                  http://www.talsystems.com

                  Comment


                  • #10
                    Continuing this discussion of FLEX strings in the other thread on that topic:

                    https://forum.powerbasic.com/forum/u...5-flex-strings

                    Comment


                    • #11
                      Continuing this discussion of FLEX strings...
                      See PB for Windows solution posted as reply to thread linked in Post#10 at https://forum.powerbasic.com/forum/u...780#post756780

                      The PB functions used there were not available in PB for MS-DOS. Flex strings are not available in PB for Windows compilers. Mission accomplished anyway.

                      MCM

                      Michael Mattias
                      Tal Systems Inc.
                      Racine WI USA
                      mmattias@talsystems.com
                      http://www.talsystems.com

                      Comment

                      Working...
                      X