|
Post by tsh73 on Nov 12, 2024 7:52:27 GMT
You don't need arrays to scan through file and get min/max Here's previous code adapted to
'enumerate files "test";str$(x);".txt"
dim info$(10, 10) files DefaultDir$, "test*.txt", info$()
nFiles = val( info$(0, 0))
mn1 = 1e10: mx1 =0-mn1
print "Files found: ";nFiles for i = 1 to nFiles file$= info$(i, 0) print i, file$, call getMinMax file$, mn, mx mn1=min(mn,mn1) mx1=max(mx, mx1) print mn, mx next print "-------------------------------------------------" print ,,mn1, mx1
sub getMinMax file$, byRef mn, byRef mx mn = 1e10: mx =0-mn open file$ for input as #f while not(eof(#f)) line input #f, aLine$ 'read whole line i = 0 while 1 'split it to words i=i+1 w$=word$(aLine$, i) if w$="" then exit while 'no more words a=val(w$) 'print a 'uncomment to see values mn=min(a, mn) mx=max(a, mx) wend wend close #f end sub
|
|
|
Post by honky on Nov 12, 2024 9:09:09 GMT
Your code diplay mn and mx (not yet adapted). What I would like to be displayed: (cell is column) mn(cell1 line1) mx(cell1 line1) mn(cell2 line1) mx(cell2 line1) mn(cell3 line1) mx(cell3 line1) ect... mn(cell1 line2) mx(cell1 line2) mn(cell2 line2) mx(cell2 line2) mn(cell3 line2) mx(cell3 line2) ect... ...ect... ...ect... It's damn not easy I did this, but I kill myself with the for and the Next for x=1 to nFiles open do$;fich$(x) for input as #g colora$="" for r=1 to nRows line input #g, donn$ col^="" for c=2 to nCols a$=a$+word$(donn$,c)+" " call tri a$,nFiles,g$,c,valu,min,max d=d+1: col$(d)=str$(min);" ";str$(max) next c colo$=colo$+col$(d)+" " ee=ee+1: colora$(ee)=colo$ print "(((((((((((((((((("'********** next r print " colora$(ee) ";colora$(ee)'******************* close #g next r return
|
|
|
Post by tsh73 on Nov 12, 2024 11:15:20 GMT
Thtat's exactly what you asked. Or so I understand.
well, that's another task BTW it will have sense only if all files are of same size, rows x columns. Do they?
(btw and it needs files to work. I think I found LB thread where files were generated...)
|
|
|
Post by honky on Nov 12, 2024 11:29:03 GMT
Yes, the files are identical.
|
|
|
Post by honky on Nov 12, 2024 11:34:34 GMT
|
|
|
Post by tsh73 on Nov 12, 2024 12:18:27 GMT
Ok, using your files
Last part of the output:
allia-fewzi 2/8 3/20 6/12 7/20 3/15 9/11 6/18 ambrosino-pascal 5/9 10/13 1/8 13/15 3/6 9/11 6/17 andre-margot 7/11 3/3 1/12 8/10 1/18 12/19 5/16 barbino-daniel 13/19 3/5 7/20 10/19 7/9 8/17 6/15 belhcen-jonathan 8/11 13/16 9/16 6/8 18/20 5/12 5/14 bello-cassandra 3/13 2/18 5/19 7/20 1/11 10/17 11/16 bels-(sarah)lisa 6/19 7/9 9/16 1/16 8/11 6/16 12/13 biguet-candys 8/13 10/12 3/9 10/20 2/17 5/17 11/13 clair-laetitia 7/14 6/20 8/13 6/16 1/17 10/19 9/14 crepel-virginie 8/19 10/14 6/16 8/14 12/16 2/11 8/15
program
'enumerate files "files\file *.txt"
dim info$(10, 10) files DefaultDir$, "files\file *.txt", info$() 'file given: 10 lines, 'name and 7 numeric columns, total 8 columns nRows=10 nCols=8
dim names$(nRows) dim mn(nRows, nCols) dim mx(nRows, nCols)
'fill arrays with initial values for r = 1 to nRows for c = 2 to nCols mn(r, c)= 1e10 mx(r, c)= -1e10 Next next
nFiles = val( info$(0, 0))
print "Files found: ";nFiles for i = 1 to nFiles file$= info$(i, 0) if i = 1 then call readNames "files\"+file$ print i, file$ call getMinMax "files\"+file$ next print "-------------------------------------------------" for r = 1 to nRows print names$(r); for c = 2 to nCols print tab(c*10);mn(r, c);"/";mx(r, c);" "; Next print next print
input "Press Enter to quit";dummy$
sub readNames file$ print "Reading names" open file$ for input as #f while not(eof(#f)) r=r+1 line input #f, aLine$ 'read whole line names$(r)=word$(aLine$,1) print r, names$(r)', aLine$ wend close #f print "names read: ";r print end sub
sub getMinMax file$ open file$ for input as #f while not(eof(#f)) r=r+1 line input #f, aLine$ 'read whole line print aLine$ c = 0 while 1 'split it to words c=c+1 w$=word$(aLine$, c) if w$="" then exit while 'no more words if c>1 Then 'skip name a=val(w$) 'print a 'uncomment to see values mn(r,c)=min(a, mn(r,c)) mx(r,c)=max(a, mx(r,c)) end if wend wend close #f print end sub
|
|
|
Post by honky on Nov 12, 2024 13:07:37 GMT
I do not understand how this madness can work, without sorting. And the craziest is that it works ! It's magic, or the witchcraft. And even more surprising, I managed to adapt it to my gas factory. It's wonderful, but I would like to understand I will work there Thank yooouuu Anatoly, my Savior.
|
|
|
Post by plus on Nov 12, 2024 14:58:21 GMT
I do not understand how this madness can work, without sorting. And the craziest is that it works ! It's magic, or the witchcraft. And even more surprising, I managed to adapt it to my gas factory. It's wonderful, but I would like to understand I will work there Thank yooouuu Anatoly, my Savior.
Yikes this is Basic 101 ' find max min of 10 numbers
dim n(10) for i = 1 to 10 n(i) = int(rnd(0)*100): print n(i);" "; next print print "Seeking max, min..."
for i = 1 to 10 ' going through array of numbers if i = 1 then max = n(i) : min = n(i) ' assign max, min first value of array else ' all others test if n(i) < min then min = n(i) ' n(i) is less than lowest found so far! make it new min if n(i) > max then max = n(i) ' n(i) is greater than greatest so far make it new max end if next
print "Max, min: "; max;", "; min
b = b + ...
|
|
|
Post by Rod on Nov 12, 2024 17:54:33 GMT
It has been said a couple of times. You either run though EVERY item and remember the lowest and highest you find OR you sort all items and read off the lowest and highest.
But if there are several files and not everything is in one sortable list then you need to use the remember process. Remember the highest you find in all the files and the lowest.
|
|
|
Post by honky on Nov 12, 2024 23:15:42 GMT
@: "tsh73": When the value of Min or Max is zero (Becaus Data Missing (**)) Would there be a way to neutralize it by referring to the following min or the previous max ?
@: "plus": I do not know enough to make manipulations of such complexity Thank you for giving me to study
|
|
|
Post by tsh73 on Nov 13, 2024 6:28:12 GMT
Just add a filter over part that counts min max:
if w$<>"**" then a=val(w$) 'print a mn(r,c)=min(a, mn(r,c)) mx(r,c)=max(a, mx(r,c)) end if
|
|
|
Post by honky on Nov 13, 2024 10:14:24 GMT
It's good. Thank you very much master Anatoly.
|
|