Re: question
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 20, 2001
- 499 views
Hi George, > > I have the following sequence, as an example. > > sequence a,b > > a = {id1,id2,id3} > > b = { > {id1,1,2}, > {id2,2,4}, > {id3,5,6} > } > > Here's the question > > if setEnable(a, False) -- works ok and disables all the id's > > Why would not > > setEnable(b[1],False) -- won't work but win32 blows up > > I would think that setEnable would cycle over the 1st element of the table > for the length of the table. This is what I have to do > > for i = 1 to length(b) > setEnable(b[i][1]) > end for > > Am I confused here? If so how could I solve the problem w/o a loop? The reason is that the first parameter to setEnable must either be a single ID number or a sequence of ID numbers. In the example you have given, the first parameter is a sequence of sequences - which is not something that I catered for. The reason being that there is no way that Win32lib could know which sub-element contains the ID. It would not be safe to assume that the first sub-element always contained the ID. However, now that you have pointed out this possibility, there is no reason why I couldn't *document* this format for those routines that take an ID as a parameter. As Mike has pointed out, there is an argument for more rigorous parameter checking in Win32lib to weed out ill formed parameters etc... The counter argument is that this just slows down the library even more and the correct parameters have been documented so it is the caller's responsibility. I do not take any position in the argument. I would like to see some form of optional parameter checking to be implemented and that is probably the way I'll go in future. However, to get around your current dilemma, try doing something like... a = {id1,id2,id3} b = { a, {1, 2, 5}, {2, 4, 6} } setEnable(b[1],False) in other words, have each sequence element represent a field rather than a record. To get the record data, you slice the sequence thus... x = find (id, a) if x != 0 then fld1 = b[2][x] fld2 = b[3][x] end if <off_topic> Now if only Euphoria had some vertical slicing syntax that would make this easier - oh well, just a pipe dream I suppose but it would be nice to do ... sequence flds flds = b[][find(id, b[1]] where a zero index would result in an empty sequence (hint, hint Robert). </off_topic> ---- Cheers, Derek.