Re: Best way to find records in sequences?

new topic     » goto parent     » topic index » view thread      » older message » newer message

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


new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu