subroutine StdPickList(FileNameList, Fmt, Selection)
* Subroutine to allow picking of an item from a translation file.
***
* Abstract:
*    This program will work with StdIn to allow selecting from a list of
* keys from any and all files used with the TRANS() special option for
* StdIn.
*
***
* Revision Log
* Who..... When.... Why...................................................
* Andrew   22Jun93  Initial coding.
*
***

FileNames = dcount(FileNameList,@FM)
if FileNames gt 1 then
   Prompt = "Please select file to pick from: "
   for i = 1 to FileNames - 1
      Prompt := i:") ":FileNameList<i>:", "
   next i
   Prompt := FileNames:") ":FileNameList<FileNames>:": "
   crt @(0,23):@(-4):
   loop
      loop
         crt @(0,22):Prompt:@(-4):
         input Res
      until num(Res) and (Res ge 1) and (Res le FileNames)
         crt @(0,23):"Please select a number from 1 to ":FileNames:"...":
      repeat
      FileName = FileNameList<Res>
      open FileName to File then
         exit
      end else
         crt @(0,23):"Unable to open ":FileName:" file.  (stdpicklist)":@(-4):
         continue
      end
   repeat
end else
   FileName = FileNameList<1>
   open FileName to File else
      crt @(0,23):"Unable to open ":FileName:" file.  (stdpicklist)":@(-4):
      return
   end
end

select File
Sorted = ""
Count = 0
loop
   readnext Key else exit
   locate Key in Sorted<1> by "AL" setting Idx else
      ins Key before Sorted<Idx>
   end
   Count += 1
   if mod(Count,100) eq 0 then crt @(0,23):fmt(Count,"R#5"):
repeat
crt @(0,23):fmt(Count,"R#5"):
Len = len(fmt("",Fmt)) + 8
Col = int(80/Len)
OnScreen = 20 * Col
Screens = int((Count/OnScreen)+.9)
Screen = 1
SaveScreen = 0
loop
   if Screen ne SaveScreen then
      BS = ""
      Error = ""
      call std.screen("STD.PICKLIST",FileName:" file pick list (screen ":Screen:" of ":Screens:")",BS,Error)
      BS := @(0,21):@(-4)
      Base = OnScreen * (Screen - 1)
      if Screen eq Screens then
         Scope = mod(Count,OnScreen)
      end else
         Scope = OnScreen
      end
      for i = 1 to Scope
         BS := @(int((i-1)/20)*Len,mod(i-1,20)+2):fmt(Base+i,"R#4) ")
         BS := Sorted<Base+i>
      next i
      crt BS:
      SaveScreen = Screen
   end
   crt @(0,22):"Which one: 1..":Count:" or S1..S":Screens:" or (N)ext or (P)revious: N":@(-4):char(8):
   input Res
   Res = upcase(Res)
   begin case
      case num(Res) and (Res ne "")
         begin case
            case Res lt 1
               crt @(0,23):"Selection cannot be less then 1...":@(-4):
            case Res gt Count
               crt @(0,23):"Selection cannot exceed ":Scope:"...":@(-4):
            case 1
               Selection = Sorted<Res>
               return
         end case
      case Res matches "S..."
         Res = Res[2,len(Res)]
         begin case
            case not(num(Res))
               crt @(0,23):"Screen number must be numeric...":@(-4):
            case Res gt Screens
               crt @(0,23):"Screen number cannot exceed ":Screens:"...":@(-4):
            case Res lt 1
               crt @(0,23):"Screen number cannot be less than 1...":@(-4):
            case 1
               Screen = Res
         end case
      case Res eq "E"
         Selection = ""
         return
      case Res eq "" or Res eq "N"
         Screen += 1
         if Screen gt Screens then Screen = 1
      case Res eq "P"
         Screen -= 1
         if Screen lt 1 then Screen = Screens
      case 1
         crt @(0,23):"Invalid response...":@(-4):
   end case
repeat
return
end
