What is the easiest way to return the number of elements in a given array?
thanks
thanks
; We will create an array with 10 positions, but we wont use them all ; We will only count those that are not empty Global arraySize = 10 Dim someArray$(arraySize) someArray$(1) = "this" someArray$(2) = "is" someArray$(3) = "one" someArray$(4) = "way" someArray$(10) = "wtf" Print returnSize() Function returnSize() Local counter = 0 For i = 1 To arraySize If someArray$(i) <> "" Then counter = counter + 1 Next Return counter End Function
Dim a$(5) a$(1) = "If it's resizeble, i'll not loose this information" Dim a$(3) Print a$(1)
type MyType Field f1, f2, f3 end type m.MyType = New MyType ; This creates a new type and m points to it m.MyType = New MyType ; This creates another new type, m now points to this but our first type still exists
m = After m ; m points to the next item in the list m = Before m ; m points to the previous item in the list m = First m ; m points to the first item in the list m = Last m ; m points to the last item in the list
myarray = NewArray(100) For i=0 To 100 SetArray myarray, i, Rand(5000) Next Print GetArray(myarray, 40) WaitKey() End ;-------------------------------------- Function NewArray(arraysize) arrbank = CreateBank(arraysize*4+4) Return arrbank End Function Function ReDim(arrbank, newsize) ResizeBank arrbank, newsize*4 End Function Function GetArray(arrbank, iCell) Return PeekInt(arrbank, iCell*4) End Function Function SetArray(arrbank, iCell, val) PokeInt arrbank, iCell*4, val End Function Function FreeArray(arrbank) FreeBank arrbank End Function
myarray = NewArray(100,100) For i=0 To 50 For j=0 To 50 SetArray myarray, i, j, i+j ; easier to check than Rand, result will be dim1+dim2 Next Next Print GetArray(myarray,10,11) WaitKey() End ;-------------------------------------- Function NewArray(dim1,dim2) arrbank = CreateBank(dim1*4+4) For k=0 To dim1 PokeInt arrbank, k*4,CreateBank(dim2*4+4) Next Return arrbank End Function Function GetArray(arrbank, d1cell,d2cell) d2bank = PeekInt(arrbank, d1cell*4) Return PeekInt(d2bank,d2cell*4) End Function Function SetArray(arrbank,d1cell,d2cell,val) d2bank = PeekInt(arrbank, d1cell*4) PokeInt d2bank, d2cell*4, val End Function
Null Parameters None Description Designates a Null Type object. Useful for making a Type variable point to nothing or checking if a Type object exists. Also, useful for checking that there are still objects left on the end of a Type list using the After command. Can used for testing and setting. See also: Type, After. Example ; Null example Type Alien Field x,y End Type a.Alien = New Alien If a <> Null Then Print "Alien exists!" Delete a if a = Null Then Print "Alien gone!"