Maximum value of a field in a queue

I have a series of records that I have loaded into a queue. The primary key field is StepId and I want to find the largest value of StepId in the queue. I could inspect each record as I load it into the queue, but I’m wondering if there is a quicker way. Also, if the queue is in a browse form, the data has already been loaded. I don’t want to have to rummage through several thousand records to find it.

In Visual Basic there is a function DMAX(“field”,“domain”,“where clause”) which returns the maximum value of a field in the domain (usually a table or query) that corresponds to the optional where clause. Similarly, Visual Basic has a DMIN function for the minimum value.

Is there a Clarion equivalent or a preferred method? I appreciate any thoughts or suggestions.
Donn

Unless you can SORT by that field, I think you’ll just be looping through the queue.

2 Likes

Do you mean doing a sort and then going to the last record, which I would find by using the RECORDS(QueName) command? Didn’t think of that.

Yes, but maybe a frequent sort would not be great for your purpose. Just depends on what you’re doing with the queue.

1 Like

QUEUEs since C5 can handle multiple sort orders. It’s enough to use any queue function with required sort parameters, for example, GET(queue,-queue.field)

If you have a queue as a FROM() in a listbox, can you sort that queue in such a way to get the largest value of a field and not disturb the listbox’s sort order? If not, I am not sure how to take advantage of the multiple sort orders.
In addition, would a SORT() change the value of CHANGES()?

Thank you.

LIST controls with a queue as a parameter of FROM uses the current sort order. Current sort order is the order set by the last SORT statement, or, if none explicit SORT has been executed, it’s the order set by the ADD statement inserted a first record to the empty queue. For example,

  FREE (que)
  ...set fields of the que...
  ADD (que)

sets current sort order to unsorted.

Usage of queues is no limited to LISTs’ FROM attributes.

No.

2 Likes

When I do something similar I add to the queue like this … ADD(Q,StepID)

After building, the last record in the queue has the highest value so I simply read it back thus … GET(Q,RECORDS(Q))

1 Like

In this case, that approach will not work because the lowest value is 100 and the highest value is 300 and there are plenty of gaps in between. I suspect RECORDS(Q) will return 21.

Still, I thank everyone who contributed, and made me think outside the box too :grinning:

In which case, GET(Q,21) will return the 21st record in the queue in its current sort order.

I believe they intended for you to use that result to GET() the queue when sorted by the value in question.

1 Like

I do not understand what you mean by this comment.
Assuming you are referring to my suggestion … the number of records in the queue is not relevant, neither are any gaps in the sequence, ADDing to the queue using the ADD(Q,Q.StepiD) method will always ensure that the very last record always has the highest value of StepID and GET(Q,RECORDS(Q)) will allow you to examine Q.StepD value.

1 Like

The Help says SORT increments CHANGES() ID and it makes sense to me that it does because the is QUEUE changed by SORT.

If any of these five statements act on the QUEUE the Change ID is incremented: FREE() ADD() PUT() DELETE() SORT()… If a SORT does not change the order the Change ID is still incremented. The Change ID is simply a count of likely changes.

Ahhh… I may have written that because I know the original Help discussing a Hash Value was wrong. I’m sure I tested it. IIRC DAB discussed CHANGES() needing to be a simple thing that indicated a “likely change”, it was not worth the effort to precisely determine changes. I use CHANGES() to decide if a LIST needs refreshing, e.g. with a VLB asking for Row -3

http://clarion.help/doku.php?id=changes_return_changed_queue_.htm


I think the best way would be to “inspect each record as I load it”

Other ways mean SORT the entire Queue, or scanning it all with a LOOP and GET. That’s more processing, especially as there are more records.

1 Like

I misread and therefore misunderstood your code. Sorry!

You’re correct. I missed some code when looked where the changes counter is incrementing.