Calculating the High and Low of it all
#15
Watch your back on Dec 25th. If your milk comes with cookies called biscottis, you might just wish you brought your elf gang along for the ride! Big Grin

Dim,

Make sure the code you are using assigns a value to "low" or what's happening is low, by default, will always be zero. The else statement, in my example, handles that condition. If that's not the case and the _round statement is causing it to be zero, try removing it, but if you do, the number format will likely be reported in scientific notation.

If you want to convert to string comparisons, and have all positive numbers that are ALL 5-digits, just do something like one of these two examples...

Code: (Select All)
FOR i = 1 TO 10
    READ DataBaseValue
    HL$ = LTRIM$(STR$(DataBaseValue))
    IF HL$ < low$ OR i = 1 THEN low$ = HL$
    IF HL$ > high$ OR i = 1 THEN high$ = HL$
NEXT
PRINT "DEMO 1: Low = "; low$; "  High = "; high$
PRINT

RESTORE
FOR i = 1 TO 10
    READ DataBaseValue
    HL$ = LTRIM$(STR$(DataBaseValue))
    IF VAL(HL$) < VAL(low$) OR i = 1 THEN low$ = HL$
    IF VAL(HL$) > VAL(high$) OR i = 1 THEN high$ = HL$
NEXT
PRINT "DEMO 2: Low = "; low$; "  High = "; high$

DATA .23675,.47623,.15345,.02365,.93456,.45637,.83423,.69374,.73214,.09399

Now if you have anything in your database that is more or less than 5-digits, negative decimals, or decimal numbers greater than 1, then the string comparison is no longer simple, and you would either have to use the second demo and test to see if the VAL() conversion holds up, or modify the first example to include a string comparison sub-routine, about 40 lines, to make accurate greater less than comparisons.

Pete
Reply


Messages In This Thread
RE: Calculating the High and Low of it all - by Pete - 10-19-2022, 05:35 PM



Users browsing this thread: 5 Guest(s)