Announcement

Collapse
No announcement yet.

problem with "array insert"-command

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

  • problem with "array insert"-command

    I am just making my first steps in PowerBasic 3.50 trying out its numerous features.
    I have written a test program that uses the "array" command. Alas the program's output doesn't meet my expectations.

    Note Ms Gollan's weight --> it's going down to zero after execution of the "array insert" command but why???
    What have I done wrong - or is this behaviour simply a bug?

    Thanks a lot for your advice!!!
    Heinz Salomon


    PROGRAM LISTING:

    'ARRAY INSERT/SORT TEST
    '======================

    type myStdType 'set up the myStdType structure
    nme as string*30
    size as byte
    weight as byte
    end type

    dim dynamic myType(1:3) as myStdType 'dimension dynamic array
    ' of type myStdType

    dim extraType as myStdType 'declare a scalar variable
    ' of type myStdType

    myType(1).nme="Heinz,Carl" 'assign data to array elements
    myType(1).size? = 192
    myType(1).weight? = 110

    myType(2).nme="Waechter,Bruce"
    myType(2).size? = 162
    myType(2).weight? = 95

    myType(3).nme="Green,Alan"
    myType(3).size? = 181
    myType(3).weight? = 86

    extraType.nme="Gollan,Carla" 'assign data to scalar variable
    extraType.size? = 179
    extraType.weight? = 54

    redim preserve myType(1:4) as myStdType 'make room for a new array element
    ' preserving the old values

    array insert myType(), extraType 'insert extraType at 1st array pos,
    ' shifting the other array elements
    ' to the array's extended end

    array sort myType(), from 32 to 32 'sort the array elements by
    ' byte value 'weight'
    ' (byte at pos 32 of
    ' the myStdType structure)


    cls 'display myType's new contents
    ?
    ?"MY FRIENDS' PHYSIOGNOMY"
    ?
    for i? = 1 to ubound(myType)
    ?" Name= "; myType(i?).nme
    ?" Size="; myType(i?).size?; "cm"
    ?" Weight="; myType(i?).weight?; "kg"
    ?
    next

    end

    THE SCREEN OUTPUT:


    MY FRIENDS' PHYSIOGNOMY

    Name= Gollan,Carla
    Size= 179 cm
    Weight= 0 kg

    Name= Green,Alan
    Size= 181 cm
    Weight= 86 kg

    Name= Waechter,Bruce
    Size= 162 cm
    Weight= 95 kg

    Name= Heinz,Carl
    Size= 192 cm
    Weight= 110 kg

    [This message has been edited by Heinz Salomon (edited September 17, 2004).]

  • #2
    I ran it here, pb/dos 3.50

    Broke here, too.

    I would send this to mailto:[email protected][email protected]</A> with the subject line "bug report."

    Seems to me ARRAY INSERT with UDT arrays was a known problem a long time ago, but I hadn't touched my PB-DOS for a couple of years before today, so that recollection is fuzzy at best.

    For a workaround...
    Code:
    'ORIGINAL==>  array insert myType(), extraType       'insert extraType at 1st array pos,
    ' replacement code:
       array insert myType()               '  insert empty element at start
       MyType(1)  = ExtraType               ' set new element value
    MCM

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

    Comment


    • #3
      Looks like a bug, all right. It's on file with R&D.

      ------------------
      Tom Hanlin, PowerBASIC Staff
      Opinions expressed may not be those of my employer or myself

      Comment


      • #4
        Mr Mattias,
        Mr Hanlin,

        thanks a lot for your helpful replies!

        Heinz Salomon

        Comment

        Working...
        X