Posts: 473
Threads: 70
Joined: Apr 2022
Reputation:
18
So, I have a massive data base of decimal value with 5 digits after the decimal. I have routine which is trying to find the highest and the lowest of these values. Here is the algorythm that I am using but for some reason it's giving me the Highest value as the Lowest and the Lowest as the Highest.
HL = DataBaseValue
If HL < 1 And HL < Low Then Low = HL
Low = (_Round(Low * 100000)) / 100000
If HL < 1 And HL > High Then High = HL
High = (_Round(High * 100000)) / 100000
The rounding is to avoid scientific notation and be sure result will be 5 digit decimal value.
I can't see why this algorythm would give the High as Low and the Low as High.
Posts: 4,698
Threads: 222
Joined: Apr 2022
Reputation:
322
If HL < 1 ??? you only want numbers less than 1?
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
The example I posted uses a double loop and swap to rank the database numbers from high to low. It's basically a non-optimized sorting routine. You can put back in the rounding, as needed. Don't let the MID$() stuff confuse you. You don't need it for your program. I put it in the demo as a way to spit out numbers. Just substitute DataBaseValue for DataBaseValue = VAL(MID$()... and you're good to use.
Pete
Posts: 4,698
Threads: 222
Joined: Apr 2022
Reputation:
322
10-18-2022, 07:37 PM
(This post was last modified: 10-18-2022, 07:37 PM by bplus.)
simply start with really low high and really high low , rnd is always < 1 so for example only
Code: (Select All)
high = -100000
low = 10
For i = 1 To 100
HL = Rnd
If HL < low Then low = HL
low = (_Round(low * 100000)) / 100000
If HL > high Then high = HL
high = (_Round(high * 100000)) / 100000
Next
Print low, high
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 473
Threads: 70
Joined: Apr 2022
Reputation:
18
Thanks guys, appreciate the help, I'll give them all a try.
Posts: 4,698
Threads: 222
Joined: Apr 2022
Reputation:
322
10-18-2022, 10:21 PM
(This post was last modified: 10-18-2022, 10:26 PM by bplus.)
low = (_Round(low * 100000)) / 100000
BTW this little trick does not work all the time, in fact it fails to return a controlled max number of decimal digits disgustingly often.
Code: (Select All)
Dim low As Double
For low = 0 To .01 Step .00001
low = (_Round(low * 100000)) / 100000
Print low
Next
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever