sync on
`set display mode 400,300,16
 
rem If you want you can put window mode on
`set window on
 
dim wordlenth(1000000)
dim word$(10)
 
maxfiletypes=2
dim filetypes$(2)
dim file$(1)
filetypes$(1)="txt"
filetypes$(2)="dat"
 
do
 
   `if filename$="" then directory$="C:\documents and settings\abc\my documents" else directory$=parentfolder$(filename$)
   `filename$=fileaccess(directory$,maxfiletypes)
   input "Directory: >";filename$
 
   words=0
   undim wordlenth(1000000)
   undim word$(10)
   dim wordlenth(1000000)
   dim word$(10)
   word$=""
   bytesscanes=0
 
   open to read 1,filename$
 
   while file end(1)=0
 
      cls
 
      word$=""
      wordlenth=0
 
      repeat
 
         read byte 1,chrASCII
 
      until letter(chrASCII)=1 or file end(1)=1
 
      if file end(1)=1 then exit
 
      repeat
 
         wordlenth=wordlenth+1
         word$=word$+chr$(chrASCII)
         read byte 1,chrASCII
 
      until letter(chrASCII)=0 or file end(1)=1
 
      if file end(1)=1 then exit
 
      words=words+1
 
      for i=1 to 9
         word$(i)=word$(i+1)
      next i
 
      word$(10)=word$
 
      wordlenth(words)=wordlenth
 
      maxlenth=0
      minlenth=0
      totallenth=0
      for i=1 to words
         if wordlenth(i)>maxlenth then maxlenth=wordlenth(i)
         totallenth=totallenth+wordlenth(i)
      next i
      minlenth=maxlenth
      for i=1 to words
         if wordlenth(i)<minlenth then minlenth=wordlenth(i)
      next i
      avglenth=totallenth/words
 
      for i=1 to 10
         ink rgb(i*25,i*25,255),0
         text 300-text width(word$(i)),i*15-15,word$(i)
      next i
 
      ink rgb(0,0,255),0
      text 0,0,"words so far: "
      text 0,15,"Maximum lenth so far: "
      text 0,30,"Minimum lenth so far: "
      text 0,45,"Average lenth so far: "
 
      ink rgb(255,255,255),0
      text 180-text width(str$(avglenth)),45,str$(avglenth)
      text 180-text width(str$(minlenth)),30,str$(minlenth)
      text 180-text width(str$(maxlenth)),15,str$(maxlenth)
      text 180-text width(str$(words)),0,str$(words)
 
      sync
 
   endwhile
 
   close file 1
 
   cls
 
   maxlenth=0
   minlenth=0
   totallenth=0
   for i=1 to words
      if wordlenth(i)>maxlenth then maxlenth=wordlenth(i)
      totallenth=totallenth+wordlenth(i)
   next i
   minlenth=maxlenth
   for i=1 to words
      if wordlenth(i)<minlenth then minlenth=wordlenth(i)
   next i
   if words>0 then avglenth=totallenth/words
 
   ink rgb(0,0,255),0
   text 0,0,"words: "
   text 0,15,"Maximum lenth: "
   text 0,30,"Minimum lenth: "
   text 0,45,"Average lenth: "
   text 0,60,"Press space to scan another..."
 
   ink rgb(255,255,255),0
   text 180-text width(str$(avglenth)),45,str$(avglenth)
   text 180-text width(str$(minlenth)),30,str$(minlenth)
   text 180-text width(str$(maxlenth)),15,str$(maxlenth)
   text 180-text width(str$(words)),0,str$(words)
 
   suspend for key
 
loop
 
function letter(ASCII)
letter=0
if ASCII>=65 and ASCII<=90 or ASCII>=97 and ASCII<=122 or ASCII>=176 and ASCII<=255 then letter=1
endfunction letter
 
function fileaccess(directory$,maxfiletypes)
 
   x=90
   y=50
 
   filename$=""
 
   while filename$=""
 
      decision=0
 
      set dir directory$
      perform checklist for files
      nooffiles=checklist quantity()
      undim file$(1)
      dim file$(nooffiles)
      sort1=1
      for i=1 to nooffiles
         temp$=checklist string$(i)
         if getfiletype$(temp$)=temp$
            file$(sort1)="[+]"+temp$
            sort1=sort1+1
         endif
      next i
      for i=1 to nooffiles
         for j=1 to maxfiletypes
            temp$=checklist string$(i)
            if getfiletype$(temp$)=filetypes$(j)
               file$(sort1)="[T]"+checklist string$(i)
               sort1=sort1+1
            endif
         next i
      next i
      for i=1 to nooffiles
         if (getfiletype$(checklist string$(i))=checklist string$(i))=0
            for j=1 to maxfiletypes
               if getfiletype$(checklist string$(i))=filetypes$(j) then goto Endfilesort
            next i
            file$(sort1)="[X]"+checklist string$(i)
            sort1=sort1+1
         endif
         Endfilesort:
      next i
 
      file=1
      list=1
      select=1
 
      while decision=0
 
         cls
 
         file=list+select-1
 
         if upkey()=1 and file>1
            if upK=0
               upK=1
               file=file-1
               if select=1 and list>1 then list=list-1
               if select>1 then select=select-1
               Ucount=40
            endif
            Ucount=Ucount-1
            if Ucount<0
               file=file-1
               if select=1 and list>1 then list=list-1
               if select>1 then select=select-1
               Ucount=2
            endif
         else
            upK=0
         endif
 
         if downkey()=1 and file<nooffiles
            if dnK=0
               dnK=1
               file=file+1
               if select=10 and list<nooffiles then list=list+1
               if select<10 then select=select+1
               Dcount=40
            endif
            Dcount=Dcount-1
            if Dcount<0
               file=file+1
               if select=10 and list<nooffiles then list=list+1
               if select<10 then select=select+1
               Dcount=2
            endif
         else
            dnK=0
         endif
 
         if mousemovez()>oldmousemovez and file>1
            file=file-1
            if select=1 and list>1 then list=list-1
            if select>1 then select=select-1
            oldmousemovez=mousemovez()
         endif
 
         if mousemovez()<oldmousemovez and file<nooffiles
            file=file+1
            if select=10 and list<nooffiles then list=list+1
            if select<10 then select=select+1
            oldmousemovez=mousemovez()
         endif
 
         if returnkey()=1 and decisionmadetime<1 then decision=2
 
         if mouseclick()=1
            if mousex()>x-1 and mousey()>y+166 and mousex()<x+108 and mousey()<y+186 and decisionmadetime<1 then decision=1
            if mousex()>x+108 and mousey()>y+166 and mousex()<x+215 and mousey()<y+186 and decisionmadetime<1 then decision=2
            for i=1 to 10
               if mousex()>x and mousey()>i*15+y and mousex()<200+x and mousey()<(i+1)*15+y
                  if doubleclickcount>0 and mouseclick=0 then decision=2
                  doubleclickcount=20
                  file=list+i-1
                  select=i
               endif
            next i
            if mousex()>x+203 and mousey()>y+16+sliderpos# and mousex()<x+213 and mousey()<y+16+sliderpos#+slidersize# and nooffiles>19
               sliderhold=1
            endif
            if mousex()>x+204 and mousey()>y+2 and mousex()<x+212 and mousey()<y+12 and file>1
               file=file-1
               if select=1 and list>1 then list=list-1
               if select>1 then select=select-1
            endif
            if mousex()>x+204 and mousey()>y+153 and mousex()<x+212 and mousey()<y+163 and file<nooffiles
               file=file+1
               if select=10 and list<nooffiles then list=list+1
               if select<10 then select=select+1
            endif
            if mousex()>x+201 and mousey()>y+14 and  mousex()<x+215 and mousey()<y+150 and blankclick<1 and nooffiles>10
               if mousey()<y+16+sliderpos#
                  if list>10
                     file=file-10
                     list=list-10
                     blankclick=10
                  else
                     if list=1
                        select=1
                     endif
                     list=1
                     file=1
                     blankclick=10
                  endif
                  tslider=0
               endif
               if mousey()>y+16+sliderpos#+slidersize#
                  if list<nooffiles-10
                     file=file+10
                     list=list+10
                     if list>nooffiles-9 then list=nooffiles-9
                     blankclick=10
                  else
                     list=nooffiles-9
                     file=nooffiles
                     select=10
                     blankclick=10
                  endif
                  bslider=0
               endif
            endif
         endif
         blankclick=blankclick-1
         doubleclickcount=doubleclickcount-1
 
         if mouseclick()=1 then mouseclick=1 else mouseclick=0
         if mouseclick()<>1 then sliderhold=0
         if sliderhold=1
               mosy1#=mousey()-(y+16)
               listsize#=(nooffiles-10)
               temp#=mosy1#/122
               listr#=temp#*listsize#
               list=listr#
               if list<1 then list=1
               if list>nooffiles-10 then list=nooffiles-10
         endif
 
         set text font "system"
         for i=1 to 10
            if select=i
               ink rgb(0,0,255),0
               box x,i*15+y,200+x,(i+1)*15+y
            endif
            ink rgb(255,255,255),0
            if (list+i-1)<=nooffiles then text x,i*15+y,file$(list+i-1)
         next i
 
         text (x+200)-text width(directory$+"\"),y,directory$+"\"
 
         ink rgb(0,0,255),0
         box x,y+168,x+106,y+184
         box x+110,y+168,x+213,y+184
 
         ink rgb(255,255,255),0
         center text x+54,y+168,"Parent folder"
         center text x+162,y+168,"OK"
 
         ink 0,0
         box 200+x,y,399,165+y
         box 0,y,x,y+200
 
         ink rgb(255,255,255),0
         linebox(x-1,y+14,x+201,y+166)
         linebox(x-1,y-1,x+201,y+14)
         linebox(x+201,y+14,x+215,y+150)
         linebox(x+201,y-1,x+215,y+14)
         linebox(x+201,y+150,x+215,y+166)
 
         linebox(x-1,y+166,x+108,y+186)
         linebox(x+108,y+166,x+215,y+186)
 
         linetriangle(x+204,y+12,x+212,y+12,x+208,y+2)
         linetriangle(x+204,y+153,x+212,y+153,x+208,y+163)
 
         if nooffiles>10
            listr#=list
            checklistquantityr#=nooffiles
            sliderpos#=listr#/(checklistquantityr#-10)
            if nooffiles<20 then sliderpos#=sliderpos#-1
            sliderpos#=sliderpos#*122
            slidersize#=10
            if list=nooffiles-9 then sliderpos#=122
            if sliderpos#>122 then sliderpos#=122
            if sliderpos#<0 then sliderpos#=0
         endif
 
         if nooffiles>10 then box x+203,y+16+sliderpos#,x+213,y+16+sliderpos#+slidersize# else box x+203,y+16,x+213,y+148
 
         ink rgb(0,0,255),0
         if nooffiles>10
            if tslider=1 then box x+203,y+16,x+213,y+14+sliderpos#
            if bslider=1 then box x+203,y+18+sliderpos#+slidersize#,x+213,y+148
         endif
 
         tslider=1
         bslider=1
 
         decisionmadetime=decisionmadetime-1
 
         sync
 
      endwhile
 
      if decision=1 then directory$=parentfolder$(directory$)
      if decision=2
         filen$=file$(file)
         if left$(filen$,3)="[T]" then filename$=directory$+"\"+right$(filen$,len(filen$)-3) : goto endfileload
         if left$(filen$,3)="[+]" then directory$=directory$+"\"+right$(filen$,len(filen$)-3) : goto endfileload
         if left$(filen$,3)="[X]"
            cls
            ink rgb(0,0,255),0
            center text 320,240,"Error - Invalid File type!"
            sleep 2000
            goto endfileload
         endif
      endif
      endfileload:
 
      decisionmadetime=10
 
      sync
 
   endwhile
 
endfunction filename$
 
function linebox(x1,y1,x2,y2)
 
   line x1,y1,x1,y2
   line x1,y2,x2,y2
   line x2,y2,x2,y1
   line x2,y1,x1,y1
 
endfunction
 
function linetriangle(x1,y1,x2,y2,x3,y3)
 
   line x1,y1,x2,y2
   line x2,y2,x3,y3
   line x3,y3,x1,y1
 
endfunction
 
function getfiletype$(filename$)
 
   filetype$=""
 
   for i=len(filename$) to 1 step -1
      if mid$(filename$,i)="." then goto filetypeend else filetype$=mid$(filename$,i)+filetype$
   next i
 
   filetypeend:
 
endfunction filetype$
 
function parentfolder$(directory$)
 
   foldernamesize=0
 
   for i=len(directory$) to 1 step -1
      foldernamesize=foldernamesize+1
      if mid$(directory$,i)="\" or mid$(directory$,i)="/" then goto parentfolderend
   next i
 
   parentfolderend:
   if foldernamesize=len(directory$) then foldernamesize=0
   parentfolder$=left$(directory$,(len(directory$)-foldernamesize))
 
endfunction parentfolder$