Announcement

Collapse
No announcement yet.

Error 466 with DIM andor REDIM

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

  • Error 466 with DIM andor REDIM

    Encountered the following conundrum considering that the documentation on REDIM states:
    AS type The AS type clause is optional, but It is recommended that an explicit variable scope clause (LOCAL/STATIC/GLOBAL/THREADED/INSTANCE) be added to each REDIM statement that uses an explicit type clause.
    Error 466 in C:\PBWin10\Huh\unhuh.bas(143:019): This name is already in use: CNTNT
    Line 143: REDIM cntnt(1 TO lynes) AS STRING

    A likely conflict is in C:\PBWin10\\Huh\unhuh.bas:
    Line 30: STATIC cntnt() AS STRING
    I tried placing a scope indicator in line 143 to no avail, not being sure where one might place it, I tried fore and aft of the array.
    Removing the 'AS STRING' from line 143 allows compilation.
    Not a really big deal, just that it doesn't seem to fit the documentation unless I'm doing something wrong.
    Any ideas?
    Rod
    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

  • #2
    Not a really big deal, just that it doesn't seem to fit the documentation unless I'm doing something wrong.
    Any ideas?
    That doc is a little weak. Becuase REDIM can be used to allocate as well as re-allocate the doc can be fuzzy.

    Personally...

    I never use scope or datatype when I am actually allocating ("DIM") or re-allocating ("REDIM"). Rather, I always define the scope and datatype in my variable declarations and always use REDIM.

    Code:
    FUNCTION Foo () AS LONG
    
      LOCAL Z() AS LONG
      GLOBAL P() AS STRING
      STATIC Q() AS DOUBLE
    
      ...
    
      REDIM Z (20)
      REDIM Q(14)
    Works here. Has for a long time, too.

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

    Comment


    • #3
      What version of PB? My PBWIn 10 doesn't say that under REDIM. It just says

      AS type The AS type clause is optional, but recommended for the purposes of clarity.

      What your quote is saying is: If you have "AS STRING" on Line 143, you should repeat the scope.
      ie REDIM cntnt(1 TO lynes) AS STATIC STRING

      But I actually do the same as MCM - Declare an un-dimensioned array initially with scope and type and then REDIM without any type (or scope). As you have discovered, that avoids the problem of having to restate the scope if you restate the type/

      Comment


      • #4
        What version of PB?
        That's important because the behavior has changed from version 2.. and 5....and 6 and 7 and 8 and 9 and 10.

        But I think the technique (declare arrays scope and type, use REDIM) Stuart and I share has worked for all the Win/32 versions (v 5+)

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

        Comment


        • #5
          Yes, normally I do as you guys do, just happened to get carried away typing while my thoughts were getting ahead of where I was. I tried putting STATIC in all spaces of the line and following the line, not one compiled. Interestingly enough, if I changed the scope in the declaration to LOCAL I never had a problem with the AS STRING in line 143.
          I'm using PBWin 10.04.
          AS STATIC STRING works so I might have avoided displacing the phrase AS STRING. I also don't recall that syntax from my travels.
          All is good.
          Rod
          In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

          Comment


          • #6
            Originally posted by Rodney Hicks View Post
            I'm using PBWin 10.04
            Hmmm, Please ignore my comment about the different Help file wording. The standard ver 10 Help file contains your "AS type" wording.

            (I'm using an updated "un-released" version of PBEdit and Help file from March this year and that line has been changed to what I quoted above.
            Guess I'll have to make sure to revert to the standard version when responding here )

            .
            AS STATIC STRING works so I might have avoided displacing the phrase AS STRING. I also don't recall that syntax from my travels.
            All is good.
            In the standard PBWIn 10 Help:
            REDIM
            REDIM uses the same basic syntax as the DIM statement.

            DIM
            DIM var[(subscripts)] [AS [GLOBAL | INSTANCE | LOCAL | STATIC | THREADED]type] [PTR | POINTER] [AT address] [, ...]

            Comment


            • #7
              Darn, just when I thought I knew everything!
              Why doesn't REDIM show that syntax if it's the same as DIM?

              Catch 22 situation here, I can't be perfect with imperfect support!
              mmmbll mmbbll mblmbl..
              Rod
              In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

              Comment


              • #8
                Originally posted by Rodney Hicks View Post
                Darn, just when I thought I knew everything!
                Why doesn't REDIM show that syntax if it's the same as DIM?
                It only has to be maintained in one place, avoiding inconsistencies!

                FWIW, I really like Eric's SQL Tools Help which says thiings like this for many (most?) of the functions:
                Except for the lDatabaseNumber& and lStatementNumber& parameters, SQL_Statement is identical to SQL_Stmt. To avoid errors when this document is updated, and to reduce the size of the Help Files, information that is common to both functions is not duplicated here.




                Comment


                • #9
                  can't be perfect with imperfect support
                  See: https://forum.powerbasic.com/forum/u...123#post808123

                  ===>

                  (Oh, hell, that's why programmers get the big bucks, right?)
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X