Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cMax 1

Status
Not open for further replies.

novice001

Programmer
Jun 7, 2002
18
US
Hello All,
I need to find maximum value in one of the fields of the table. I open it using tCursor, and use cMax to get the maximum:

tcData.open(":data:table")
tcData.edit()
nuValue = tcData.cMax("field 1")

It works fine, however, i'm afraid this can fail in multiuser environment, because cMax requires full lock on the table. Is there any alternative to this function?
Thank you
 
novice001,

You are correct, cMax() requires exclusive access for an accurate result, which pretty much limits its use in a multi-user situation to private answer tables or cloned cursors. You do have several options to choose from:

1. Walk through the table, e.g:

Code:
tcData.open(":data:table")
nuValue = 0
scan tcData : 
   nuValue = nuValue + tcData."field 1"
endScan
tcData.close()

2. Use a QBE query:

Code:
nuValue = 0
qryMax = QUERY

   :DATA:TABLE | FIELD 1      |
               | CALC MAX ALL |

endQuery
if not qbeMax.execute( tcAnswer ) then
   errorShow( "Query Problem", "See [>>] for details..." )
else
   nuValue = tcAnswer.(1)
endIf
return nuValue

3. Use a SQL query (similar to the above, only you replace the QBE variable with a SQL variable populated with appropriate syntax.

4. Make a temporay copy of the current table in the user's :pRIV: folder and then cMax() that.

5. Drop a hidden, calculated field on your form, make sure all edits are posted, assign it as a Max() summary field, and then grab the
Code:
Value
property at run-time.

Each of these offers certain benefits and disavantages for various situations. Hopefully, one of them will work for your needs.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top