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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get the max or mini value to parameter

Status
Not open for further replies.

ameedoo3000

IS-IT--Management
Sep 20, 2016
233
EG
hi all
how can i get the max value or the mini value from the field and put it to parameter.
i try this code and didn't Benefit.

a = max(field name)
b = mini(field name)
c = a-b
thisform.text1.value = transform(c)

Of course there was an error message!
what the correct code to do that?
 
Check Calculate in Help.

[pre]Calculate Max(FieldName) to lnMax && a, b and c are illegal as memory variable names!
Calculate Min(FieldName) to lnMin
[/pre]
 
Beware, there also is the MAX() function as you used it, but this will take two parameters and return the higher one (MIN of course the lower one) and is not relted to tables or workareas. Then there is CALCULATE as shown and then you can SELECT MAX(field) from table, also per group in a GROUP BY SQL qurey, which differs from the MAX function in only taking one field (or expression) and returning the max of a group of records (or all records), but only within SQL, as that is part of SQL and not of VFPs own functions.

a-j are addressing workareas, you can use them as variables, but it is not at all recommended. Using variables with VFP name conventions will make the shortest Variable names have 3 letters anyway, and even if you don't want to follow the pattern of a prefix and have straight names, it is not only best practice, but one of least things to do to be able to understand even own code, to be verbose in names. To the compiler any name is just one symbol, so it doesn't make code run slower nor does code using short variable names run faster. Never be lazy, it never pays.

Bye, Olaf.

 
Thank you very much. Dear Tbleken and Dear Olaf. The experience was successful and I benefited a lot and a lot. I have achieved my goals at the moment using Calculate Max(), and everything is fine and thank Mr.Olaf for the wonderful addition and wonderful useful ...
Greetings to all .
Ahmed
 
Actually, you can even do all of this in only two lines:

[pre]Select max(fieldname), min(fieldname) from yourtable into array laDummy
thisform.text1.value = transform(laDummy(1)-laDummy(2))[/pre]
 
this idea is very beautiful, wonderful and easy.
Thank you very much Dear tbleken.
Greetings.
Ahmed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top