Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDT problems
#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


Messages In This Thread
UDT problems - by eoredson - 11-12-2023, 05:46 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 05:49 AM
RE: UDT problems - by eoredson - 11-12-2023, 06:05 AM
RE: UDT problems - by mnrvovrfc - 11-12-2023, 06:33 AM
RE: UDT problems - by SpriggsySpriggs - 11-12-2023, 06:19 AM
RE: UDT problems - by eoredson - 11-12-2023, 06:42 AM
RE: UDT problems - by SMcNeill - 11-12-2023, 06:58 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 06:44 AM
RE: UDT problems - by eoredson - 11-12-2023, 06:50 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 06:57 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 06:54 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:02 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:09 AM
RE: UDT problems - by SMcNeill - 11-12-2023, 07:20 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:22 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 07:25 AM
RE: UDT problems - by SpriggsySpriggs - 11-12-2023, 07:27 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:48 AM
RE: UDT problems - by justsomeguy - 11-12-2023, 11:06 AM
RE: UDT problems - by eoredson - 11-12-2023, 11:41 PM
RE: UDT problems - by eoredson - 11-13-2023, 12:38 AM
RE: UDT problems - by SMcNeill - 11-13-2023, 12:52 AM
RE: UDT problems - by justsomeguy - 11-13-2023, 12:58 AM
RE: UDT problems - by eoredson - 11-13-2023, 01:34 AM
RE: UDT problems - by SMcNeill - 11-13-2023, 02:34 AM
RE: UDT problems - by mnrvovrfc - 11-13-2023, 01:48 AM
RE: UDT problems - by eoredson - 11-13-2023, 01:59 AM
RE: UDT problems - by justsomeguy - 11-13-2023, 02:18 AM
RE: UDT problems - by eoredson - 11-13-2023, 02:26 AM
RE: UDT problems - by eoredson - 11-13-2023, 02:52 AM
RE: UDT problems - by justsomeguy - 11-13-2023, 04:57 AM
RE: UDT problems - by eoredson - 11-13-2023, 05:20 AM



Users browsing this thread: 9 Guest(s)