Thanks Petr, your program is a perfect candidate for OOP. Without it you have to work quite hard behind the scenes to make it all run smoothly.
Below is a work in progress, which I hope goes most of the way in encapsulating your concept. Each list is a single object and takes string elements, and it should be possible to extend the class generically for any type of element. (good for testing O2 and trapping bugs anyway!)
[code=thinbasic]
'=========
class list
'=========
'
protected
'
ls as string 'list content
sz as sys 'unit size of element
ct as sys 'count of elements stored
'
public
'
method Create(sys n) { ls="" : sz=n }
method Clear() { ls=nuls ct*sz : ct=0 }
method Destroy() { ls="" : ct=0 : sz=0 }
method SetAmount(sys n) { ls=nuls sz*n }
method Add(el as string) { a=ct*sz+1 : mid this.ls,a,el : ct+=1 }
method Get(sys n) as string { a=(n-1)*sz : return mid ls,a+1,sz }
method Insert(string el,sys n) { a=sz*n : ls=left(ls,a)+el+mid(ls,a+1) : ct+=1 }
method Delete(string el,sys n) { a=sz*n : ls=left(ls,a)+mid(ls,a+1) : ct-=1 }
method Count() as sys { return ct }
method Elsize() as sys { return sz }
method Length() as sys { return len(ls) }
end class
[/code]
Bookmarks