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).]
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).]
Comment