> DIM realArray(1 TO 15) AS LONG AT VARPTR(Rec.Item(1))
....
>I'm not sure if it also applies to PBDOS
Yes, the principle applies, but the syntax is a little different.
See post#6 this thread.
MCM
Announcement
Collapse
No announcement yet.
Is This UDT Correct
Collapse
X
-
The thing you need to keep in mind with arrays in UDTs is that you can't use the array commands on them. ARRAY ASSIGN, ARRAY DELETE, ARRAY INSERT, ARRAY SCAN, ARRAY SORT or ARRAYATTR. They aren't stored as regular PB arrays which is why Michael Mattias refers to them as tables instead. You can use those commands if you create an absolute array at the location of the "array" in the UDT using a command like this:
Code:DIM realArray(1 TO 15) AS LONG AT VARPTR(Rec.Item(1))
Leave a comment:
-
PB DOS 3.5 (don't know about other versions) indeed allows arrays in UDTs: I have used them a lot in the past.
Leave a comment:
-
Certainly Type/End Type structures in PBDOS accept FIXED LENGTH strings, even in PB3.1, but AFAIK, as Rodney pointed out, not variable length strings.
On the other hand in PB31 you can have an Array of types, but you can't include arrays within a Type, which in PB3.5 is perfectly possible
Also note that in PB3.1 the underscore is not allowed within the variable names
PB3.1
Code:CLS TYPE RecStock Cust AS STRING*14 Item AS LONG Price AS LONG END TYPE DIM Rec(0 to 15) AS RecStock FOR I%=0 TO 15 Rec(I%).Cust="NOT DISCLOSED" Rec(I%).Item=5*I% Rec(I%).Price=I%*1000 NEXT I% CALL MySub(Rec()) END SUB MySub(Rec() AS RecStock) FOR I%=1 TO 15 Print Rec(I%).Cust;CHR$(32);Rec(I%).Item;CHR$(32);Rec(I%).Price NEXT I% END SUB
PB3.5
Code:CLS TYPE Rec_Stock Cust(1 TO 15) AS STRING*14 Item(1 TO 15) AS LONG Price(1 TO 15) AS LONG END TYPE DIM Rec(10) AS Rec_Stock FOR J%=1 TO 10 FOR I%=1 TO 15 REC(J%).Cust(I%)="NOT DISCLOSED" Rec(J%).Item(I%)=I%*J% Rec(J%).Price(I%)=J%*1000 NEXT NEXT CALL MySub(Rec()) END SUB MySub(Rec() AS Rec_Stock) FOR J%=1 TO 10 FOR I%=1 TO 15 Print Rec(J%).Cust(I%);CHR$(32);Rec(J%).Item(I%);CHR$(32);Rec(I%).Price NEXT NEXT END SUB
Last edited by Manuel Valdes; 16 Oct 2009, 10:30 AM.
Leave a comment:
-
Originally posted by José Roca View PostPB DOS 3.5 (don't know about other versions) indeed allows arrays in UDTs: I have used them a lot in the past.
Leave a comment:
-
PB DOS 3.5 (don't know about other versions) indeed allows arrays in UDTs: I have used them a lot in the past.
The program works as expected:
Code:TYPE Rec_Stock Cust AS LONG Item(1 TO 15) AS LONG Price(1 TO 15) AS LONG Ount(1 TO 15) AS LONG END TYPE DECLARE SUB MySub(Rec AS Rec_Stock) DIM Rec AS Rec_Stock DIM I AS INTEGER FOR I%=1 TO 15 Rec.Item(I%)=0 NEXT I% ' Now, I 'm ASKING ' 1. IF THIS UDT CORRECT ? ' 2. IF Yes, INSIDE THE SUB ,THE VALUE ARE NOT ZERO , WHY? ' CALL SUB MySub rec END SUB MySub(Rec AS Rec_Stock) DIM I AS INTEGER FOR I%=1 TO 15 IF Rec.Item(I%)=0 THEN ITERATE FOR ' THE VALUE IN NOT 0 ,WHAT IS WORNG? PRINT Rec.Item(I%) NEXT I% END SUB ' Of MySub
Leave a comment:
-
From the manual:
An element in a TYPE/END TYPE type can be any PowerBASIC type except an array or variable-length string.
Leave a comment:
-
Dery:
Thinking further, may be you were expecting to see the message "It's not 0, what is wrong?" so as to see how the instruction ITERATE works.
If so, you have to remove the "comment ' " , and put a Print instead.
Regards,
Leave a comment:
-
Dery:
I compiled your code slightly modified with PB35 and think it works right
Code:CLS TYPE Rec_Stock Cust AS LONG Item(1 TO 15) AS LONG Price(1 TO 15) AS LONG Ount(1 TO 15) AS LONG END TYPE DIM Rec AS Rec_Stock FOR I%=1 TO 15 Rec.Item(I%)=0 ' put here whatever value NEXT I% MySub Rec END SUB MySub(Rec AS Rec_Stock) FOR I%=1 TO 15 Print Rec.Item(I%) ' actually print the right value If Rec.Item(I%)= 0 then ITERATE Print "It's not 0, What is wrong?" NEXT I% END SUB ' Of MySub
Last edited by Manuel Valdes; 8 Oct 2009, 10:28 AM.
Leave a comment:
-
>If I remember correctly PBdos udt's do not allow arrays in the udt.
I think you may be right about that (can't find any reference to tables/arrays in the PB/DOS help file)... but then, how did the program compile?
Regardless you could use an absolute array to simulate this...
Code:TYPE Rec_Stock Cust AS LONG ITEMX AS STRING * 60 ' size of 15 four byte LONGs PriceX AS STRING * 60 ' ditto OuntX AS STRING * 60 ' ditto END TYPE DIM Item_Rec AS Rec_stock DIM ABSOLUTE ITEM (1 to 15) AS LONG AT VARPTR32(Item_Rec.ItemX) FOR Z = 1 TO 15 Item(Z) = value NEXT
Can't remember if you are supposed to DEF SEG somewhere and DIM AT VARPTR, or just use the segffset form of address packed as a VARPTR32().
MCM
Leave a comment:
-
If i remember correctly PBdos udt's do not allow arrays in the udt.
KS
Leave a comment:
-
Hopefully, code above is closer to DOS.
Please place your program within code tags so we can copy and paste it.
Posted code block should start with CODE enclosed within brackets.
The code block should end with /CODE enclosed within brackets.
Note:
Code placed within a code block can later be copied by others by
holding down the ctrl key and left-clicking to the left or right of the code block area.
A DOS person will have to help since your code works with PBWin9.Last edited by Mike Doty; 8 Oct 2009, 07:03 AM.
Leave a comment:
-
Code:TYPE Rec_Stock Cust AS LONG ITEM(1 TO 15) AS LONG Price(1 TO 15) AS LONG Ount(1 TO 15) AS LONG END TYPE DIM Rec AS Rec_Stock Rec.Item(15) = 999 CALL MySub(Rec) SUB MySub(Rec AS Rec_Stock) DIM I AS INTEGER FOR I=1 TO 15 IF Rec.Item(I)=0 THEN PRINT "I =" + STR$(i):ITERATE FOR PRINT "AFTER ITERATE" + STR$(Rec.ITEM(i)) NEXT I END SUB
Last edited by Mike Doty; 8 Oct 2009, 06:53 AM.
Leave a comment:
-
Is This UDT Correct
TYPE Rec_Stock
Cust AS LONG
Item(1 TO 15) AS LONG
Price(1 TO 15) AS LONG
Ount(1 TO 15) AS LONG
END TYPE
DIM Rec AS Rec_Stock
FOR I%=1 TO 15
Rec.Item(I%)=0
NEXT I%
' Now, I 'm ASKING
' 1. IF THIS UDT CORRECT ?
' 2. IF Yes, INSIDE THE SUB ,THE VALUE ARE NOT ZERO , WHY?
' CALL SUB
MySub rec
END
SUB MySub(Rec AS Rec_Stock)
FOR I%=1 TO 15
IF Rec.Item(I%)=0 THEN ITERATE FOR
' THE VALUE IN NOT 0 ,WHAT IS WORNG?
NEXT I%
END SUB ' Of MySubTags: None
Leave a comment: