Re: Best way to find records in sequences?
- Posted by Evan Marshall <1evan at sbcglobal.net> Jul 08, 2006
- 587 views
ZNorQ wrote: > > Pete Lomax wrote: <snip> > > > > > This is what I usually do: > > }}} <eucode> > > sequence Emsgs > > Emsgs={} > > integer Eused > > Eused = 0 > > function emsg(sequence txt) > > Eused+=1 > > if Eused>length(Emsgs) then > > Emsgs&=repeat(0,32) > > end if > > Emsgs[Eused]=txt > > return Eused > > end function > > I'm having a real hard time understanding the above code. Well, more the > use of 'if' and 'repeat'. Why whould this be necessary? As far as I can > see, the 'if' would ALWAYS be executed as Eused would be larger than the > length of Emsgs.. Well, unless Emsgs was tampered with manually - but > that could go in any direction - either shorten the content, or adding to > it. And why repeat 32 zeroes before adding the actual text? <snip> > > Kenneth The if statement would setup a sequence called 'Emsgs' with a length of 32. Then Eused would be shorter then length(Emsgs). This function wouldn't work if Eused was greater than 32, after that you would get a subscript error. Wouldn't this be a better way:?
sequence Emsgs Emsgs={} function emsg(sequence txt) Emsgs = append(Emsgs,txt) return length(Emsgs) end function