Announcement

Collapse
No announcement yet.

ARRAY DELETE W/ MULTI-DIMENSIONAL ARRAYS

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

  • ARRAY DELETE W/ MULTI-DIMENSIONAL ARRAYS

    Please help. I am not a grand programmer, but then I've heard that bumblebees are not supposed to be able to fly either! I'm tying to delete a portion of a random access file. The only way I could figure out how to do it is to convert it to an array, KILL the file, ARRAY DELETE the column, and then write it back to the file. Everything is cool except the ARRAY DELETE. It scrambles everything. Anyway, here is the code for anyone who is interested in helping.
    (DIM and all the other stuff has already been done)

    FOR X=1 TO END_OF_FILE 'fill the array with the contents of the UPS file
    GET #8,X
    FOR Y=1 TO 8
    TEMP$(Y,X)=UPS$(Y)
    NEXT Y
    NEXT X
    CLOSE #8
    CALL CLEAR_UPS ' kills the UPS file
    CALL UPS_OPEN ' opens the UPS file
    FOR Y=1 TO 8
    ARRAY DELETE TEMP$(Y,SE) 'delete the dealer at index SE
    NEXT Y
    FOR X=1 TO END_OF_FILE-1 'put it back in the file
    FOR Y=1 TO 8
    LSET UPS$(Y)=TEMP$(Y,X)
    NEXT Y
    PUT #8,X
    NEXT X
    CLOSE #8


    [This message has been edited by Bill Franke (edited April 13, 2002).]

  • #2
    Internally, a multi-dimension array is stored in column-major sequential order.

    When using ARRAY DELETE (or any of the array statements) with a mult-dimension array, you must use the FOR clause to limit the number of subscripts that are affected.

    Please play with this example to get some idea of how to change your code:
    Code:
    cls
    defint a-z
    dim a(1:10,1:10)
    for y = 1 to 10
      for x = 1 to 10
        a(x,y) = x * 10 + y - 10
      next
    next
    
    for y = 1 to 10
      for x = 1 to 10
        print using$("### ",a(x,y));
      next
      print
    next
    
    print
    
    ' Clear a column by deleting and inserting 0 subscripts
    ' 10 subscripts wide, and we are deleting column 2, so 9 subscripts will be
    ' affected for each DELETE operation to limit it to one column
    for y = 1 to 10
      array delete a(2,y) for 9    ' we use 9 because 10 - 2 + 1 = 9
      array insert a(2,y) for 9, 0
    next
    
    for y = 1 to 10
      for x = 1 to 10
        print using$("### ",a(x,y));
      next
      print
    next
    I hope this helps!


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

    Comment

    Working...
    X