DEFLNG A-Z
TYPE t
s AS STRING
END TYPE
DIM v AS t
FOR i = 10 TO 0 STEP -1
set v.s, i, i ^ 2
NEXT i
FOR i = 0 TO 10
PRINT get(v.s, i)
NEXT i
SUB set (array$, index, value&)
element_size = LEN(value)
IF LEN(array$) < element_size * (index + 1) THEN
array$ = array$ + STRING$(element_size * (index + 1) - LEN(array$), CHR$(0))
END IF
MID$(array$, index * element_size + 1) = _MK$(LONG, value)
END SUB
FUNCTION get& (array$, index)
get = _CV(LONG, MID$(array$, index * LEN(get) + 1, LEN(get)))
END FUNCTION
(Change the &s and the 'LONG's to whatever data type you want).That seems like an overly complicated way to store many pieces of data in a string. Leaving the Aname label aside for the moment, this is a much simpler way to do it:Code: [Select]DEFLNG A-Z
(Change the &s and the 'LONG's to whatever data type you want).
TYPE t
s AS STRING
END TYPE
DIM v AS t
FOR i = 10 TO 0 STEP -1
set v.s, i, i ^ 2
NEXT i
FOR i = 0 TO 10
PRINT get(v.s, i)
NEXT i
SUB set (array$, index, value&)
element_size = LEN(value)
IF LEN(array$) < element_size * (index + 1) THEN
array$ = array$ + STRING$(element_size * (index + 1) - LEN(array$), CHR$(0))
END IF
MID$(array$, index * element_size + 1) = _MK$(LONG, value)
END SUB
FUNCTION get& (array$, index)
get = _CV(LONG, MID$(array$, index * LEN(get) + 1, LEN(get)))
END FUNCTION
You could rewrite this to use _MEM too, but I don't consider any speed gain to be worth the extra complexity of manual memory management, especially once you start building arrays of UDTs or passing the UDT around as an intermediate value.
array$ = array$ + STRING$(element_size * (index + 1) - LEN(array$), CHR$(0))
@bplus . I see now what you mean by splitting up one long string name into the various names for the arrays I would like my program to develop on the fly. So, in the example I was using, if I forsee the user of the program could manipulate the various files of data into their Mean, Mode, Median, MovingMean, MovingMode, MovingMedian, with periods of 4, 10, 25 and knowing i have 50 files all with the same name but for the event file number then one massive array containing all that info could be used to form the exact array the user would request.
So
Query$ = "MeanModeMedianMovingMeanMovingModeMovingMedian41025Event1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950"
Then invite the user to chose the Event and Math function to display the data, and using that info create a sub array from Query$ and the file name to access. I'll give it a go. It is dealing with string values ie Dim Shared MovingMedian4 (1 to 300) wouldn't work - has to be Dim Shared MovingMedian4$(1 to 300) and the data it's accessing has to be in quote marks.
TYPE a_type
foo AS STRING * 104
END TYPE
DIM ex AS a_type
DIM array(100) AS LONG
DIM m(1) AS _MEM: m(1)= _MEM(array()): m(0) = _MEM(ex)
FOR i = 0 TO 100
array(i) = i ‘do whatever with the array.
NEXT
_MEMCOPY m(1), m(1).OFFSET, m(1).SIZE TO m(0), m(0).OFFSET ‘copy the array to the proper position in the TYPE
‘do whatever with the UDT variable such as putting it to a file.
Seems like you can do away with the line(s)Code: QB64: [Select]
As a_type isn't mentioned subsequently. Is this really arrays in types?
Line 68 needs to say INTEGER.
I generally just accept the extra space usage of longs in order to get their extra range and prevent overflow, but to reach their own.
That is so cool aplus . mega beyond what I had in mind but oh so cool.
This looks interesting, but I'm too bogged down at the moment to get sidetracked. I hope to revisit it soon.
I also love the shameless advertising of marking your own posts as the Best Answer. Keep in mind, as per our previous conversation,I'm more than happy to do that for you, but my fee is my fee! :D
Pete
I do have a question about Len(get) in this:Code: QB64: [Select]
That really work? using the function name most curious!