Announcement

Collapse
No announcement yet.

A strange dim

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

  • A strange dim

    I write a little bigger program
    (circa 7000 lines).

    There is next segment of code in the begining:

    Dd = 21
    dim sit$(dd)
    dim sd(dd, dd), sur$(dd), xaus(dd), sum(dd), pamet(dd, dd), pamet2(dd, dd), pamet3(dd)
    dim vp(dd, dd), difer(dd, dd), d(dd), diference(dd)
    dim h(dd), draft(dd), po$(dd)
    dim z(dd), vrchol(dd, dd), extreem(dd), c(dd), r(dd), sum1(dd), sum2(dd)
    dim bod$(16)
    dim dynamic help(dd)

    In the middle of program is second segment:

    for I = 1 to Nsit
    read A$
    if eof(3) = 0 then
    input # 3, B$
    else
    B$ = ""
    end if

    ' permanet error "subscript out of range" appears in next line
    sit$(I) = A$
    A$ = REMOVE$(a$, " ")

    B$ = REMOVE$(b$, " ")
    if A$ <> B$ then
    Neshoda2 = Neshoda2 + 1
    if Neshoda2 = 1 then
    locate 7, 1
    call CENTRUJ ("Founded sieve errors:")
    print
    end if
    print repeat$(11 - len(str$(I)), " "); remove$(str$(I), " "); "."; TAB(14); "sieve"; TAB(25); " Expected "; A$; TAB(45); " Founded: "; B$
    end if
    next I

    There is a compilation error (No. 7) in the second segment (see remark) .

    In fact a variable Nsit = 14. A what is strangest?

    If

    Dd=21
    dim sit$(dd)

    is changed on

    Dd=21
    dim sit$(21)


    all work fine!


    Why?
    Lubos


    ------------------
    Lubos
    http://web.fsv.cvut.cz/cp1250/~svobodal/basic/
    Lubos
    A view on PowerBASIC

  • #2
    is a compilation error (No. 7) in the second segment (see remark) .
    I've never seen error 7 at COMPILE time, but error 7 in the help file says,
    Error 7: Out of memory

    Can be caused by dimensioning too large an array or using up all
    string space.
    If you get an error 7 on a DIM/REDIM () statement, the array is not created, and attempts to reference elements of the array will always result in a subscript out of range error.

    Test/Debug procedure:
    Include error handler in the section of code which allocates the arrays (the DIM statements). If you are getting error 7 there, you'll have to rethink your design. (DIM VIRTUAL can help here).

    MCM


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

    Comment


    • #3
      Yes, it certainly sounds like low memory condition issues.
      • DIM sit$(dd) --> this is a DYNAMIC array created at run-time if memory exists.
      • DIM sit$(21) --> this is a STATIC array created at start-up, if memory exists.

      PS: Adding $ERROR ALL ON is a good start to ensure that all possible error trapping is being utilized to help track the problems down.




      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Hi Michael and Lance,

        thank you for advice and explanation.

        Lubos

        ------------------
        Lubos
        http://web.fsv.cvut.cz/cp1250/~svobodal/basic/
        Lubos
        A view on PowerBASIC

        Comment

        Working...
        X