Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDT problems
#11
(11-12-2023, 06:42 AM)eoredson Wrote:
(11-12-2023, 06:19 AM)SpriggsySpriggs Wrote: He's saying it isn't able to be done. Also, it isn't something worth implementing.
Yet QB64PE claims to be QB45 compatible which has UDT arrays...

Is a question of principle.

I'd like to see a screenshot of an array in QB45.   It sure doesn't work on the version which I keep around for testing things out on!

[Image: image.png]


[Image: image.png]
Reply
#12
(11-12-2023, 06:54 AM)TerryRitchie Wrote: If you need bits (presumably as flags) you could always use a _BYTE and manipulate each of the 8 bits. This will give you 8 flags to choose from.

Code: (Select All)
TYPE BitStruct
    xbits AS _BYTE
END TYPE

DIM BitsStructure AS BitStruct

BitsStructure.xbits = BitsStructure.xbits XOR 8 ' toggle 4th bit

PRINT BitsStructure.xbits

BitsStructure.xbits = BitsStructure.xbits XOR 8 ' toggle 4th bit

PRINT BitsStructure.xbits
Yes, an _Byte would work.
Reply
#13
Ok, In PDS 7.10 the following works:

[Image: struct.png]

I will admit there are not any in QB45.
Reply
#14
I don't think we ever claimed to be PDS compatible.  We just shoot for QB45 as much as possible.  Big Grin
Reply
#15
(11-12-2023, 07:20 AM)SMcNeill Wrote: I don't think we ever claimed to be PDS compatible.  We just shoot for QB45 as much as possible.  Big Grin

Well then : that invalidates my whole entire thread Huh
Reply
#16
(11-12-2023, 07:22 AM)eoredson Wrote:
(11-12-2023, 07:20 AM)SMcNeill Wrote: I don't think we ever claimed to be PDS compatible.  We just shoot for QB45 as much as possible.  Big Grin

Well then : that invalidates my whole entire thread Huh
Arrays in UDTs can be replicated using _MEM. I've seen more than one discussion on the topic and I believe someone even created a library for it, although I can't remember who that was right now.

If I remember correctly one of the discussions went into great detail on how to implement _MEM as an array replacement.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#17
Or you can just use strings. Or any variable larger than the one you want to use.
Tread on those who tread on you

Reply
#18
I have been using this method to store an array in an UDT:

Code: (Select All)
' define an array as string.
Type Datatype
  Array As String * 16
End Type
Dim DataRecord As Datatype
Dim Array(8) As Integer
' store array.
For L = 1 To 8
  Array(L) = L
Next
' put array into UDT string.
For L = 1 To 8
  Mid$(DataRecord.Array, (L - 1) * 2 + 1, 2) = MKI$(Array(L))
Next
' get array from UDT string.
For L = 1 To 8
  M = CVI(Mid$(DataRecord.Array, (L - 1) * 2 + 1, 2))
  Print M;
Next
End

If somebody could point out to me how I could do this using _MEM I would like to see it..
Reply
#19
Code: (Select All)
' Program to create an array of Doubles in a UDT
DIM AS LONG i
DIM AS DOUBLE v
CONST cMAXELEMENTS = 10

TYPE tARRAY
  array AS _MEM
END TYPE

DIM AS tARRAY object

' initialize the array
createObject object

' set the array to random values
FOR i = 0 TO 10
  v = RND * 5
  setElement object, i, v
  PRINT "index:"; i; "->"; v
NEXT

' retrieve vales from array
FOR i = 0 TO 10
  PRINT "index:"; i; "->"; getElement(object, i)
NEXT


SUB createObject (o AS tARRAY)
  ' make array one larger than number of elements
  o.array = _MEMNEW((cMAXELEMENTS + 1) * 8) ' 8 is the number of bytes in a double
END SUB

FUNCTION getElement# (o AS tARRAY, element AS LONG)
  getElement = _MEMGET(o.array, o.array.OFFSET + (element * 8), DOUBLE)
END FUNCTION

SUB setElement (o AS tARRAY, element AS LONG, v AS DOUBLE)
  _MEMPUT o.array, o.array.OFFSET + (element * 8), v AS DOUBLE
END SUB

Is this what you are looking for?
Reply
#20
That may help.

btw: is
Code: (Select All)
array AS _MEM
 
variable length?
Reply




Users browsing this thread: 11 Guest(s)