Announcement

Collapse
No announcement yet.

Dim, Redim At

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

  • Michael Mattias
    replied
    Explanation:
    Code:
    LOCAL  X() AS whatever
    Tells compiler, which reads top to bottom, "Whenever you see the symbol 'X' in this procedure it means an array of whatevers"

    NOte: you may need to physically place a REDIM statement prior to any use of X() in the procedure to avoid an 'array not dimensioned' error. (I never figured out the actual rules used). But that's easy enough...
    Code:
    FUNCTION Foo ( ......
     LOCAL X() AS whatever
     LOCAL  I, J, K AS LONG
     ...
    ' == END VARIABLE DECLARATIONS, START CODE  ====
      REDIM X(0) 
    
     ' REAL CODE STARTS HERE
    ....
    MCM

    Leave a comment:


  • Michael Mattias
    replied
    REDIM without an initial DIM sometimes won't compile. IS it OK to DIM without the AT qualifier then REDIM AT?
    Code:
     FUNCTION Foo( params) as Something
    
      LOCAL  X() AS whatever
      ....
    .....
    .....
        REDIM X (number) AT address
    MCM

    Leave a comment:


  • Chris Holbrook
    replied
    Yes, you're probably right. It seemed to work for me too, but I got a bit suspicious of it after making a GPF go away by using an initial DIM. Next time I will keep the original code, so don't ask!

    The application has been rewritten without using a DIM/REDIMed array.

    I don't like arrays very much.

    Leave a comment:


  • John Gleason
    replied
    The code below shows yes, and yes to the 2 questions. I didn't have a problem compiling with REDIM only, have you got a code example that won't compile?
    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    
        LOCAL myString AS STRING, ii AS LONG, ptrMyString AS BYTE PTR
        myString = SPACE$(5000000)
        ptrMyString = STRPTR(myString)
        FOR ii = 1 TO 5000000
           @ptrMyString = ii MOD 256 'long repeating string
           INCR ptrMyString
        NEXT
           
        REDIM a(1000000) AS LONG
        REDIM a(1000000) AS LONG AT STRPTR(myString)
        ? STR$(a(500000))
        REDIM a(1000000) AS LONG AT STRPTR(myString) + 500000
        ? STR$(a(500000))
    
    END FUNCTION
    Last edited by John Gleason; 10 Sep 2008, 04:17 PM. Reason: ii = 1 to 5000000, not 0 to 5000000

    Leave a comment:


  • Chris Holbrook
    started a topic Dim, Redim At

    Dim, Redim At

    Two questions:

    1. Is it acceptable to REDIM...AT to a different AT address from the previous one?

    2. REDIM without an initial DIM sometimes won't compile. IS it OK to DIM without the AT qualifier then REDIM AT?
Working...
X