home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk463.lzh / FileIO / BASIC / MultipleList (.txt) < prev    next >
AmigaBASIC Source Code  |  1991-03-09  |  7KB  |  169 lines

  1.  CLS
  2.  LOCATE 1,8
  3.  PRINT "Demo AmigaBasic program using MULTIPLE_SELECT FileIO requester"
  4.  LOCATE 2,11
  5.  PRINT "Mercilessly hacked together by Jeff Glatt (68000 asm dissidude)"
  6.  
  7.  DEFLNG a-Z  'IMPORTANT! All variables are longs (for the library calls)
  8.  
  9.  'requester.bmap and exec.bmap must be in the current directory
  10.  LIBRARY "requester.library"
  11.  LIBRARY "exec.library"
  12.  
  13.  DECLARE FUNCTION AllocMem() LIBRARY
  14.  
  15.  DECLARE FUNCTION DoFileIOWindow() LIBRARY  'These are FileIO lib routines
  16.  DECLARE FUNCTION GetFileIO() LIBRARY  
  17.  DECLARE FUNCTION AutoFileMessage() LIBRARY
  18.  DECLARE FUNCTION AutoPrompt3() LIBRARY
  19.  DECLARE FUNCTION AddEntry() LIBRARY
  20.  DECLARE FUNCTION RetrieveEntry() LIBRARY
  21.  
  22.  'For SPECIAL_REQ, we don't need a buffer for the pathname.
  23.   
  24.  FileIO=GetFileIO(0)  'Get the address of the FileIO structure
  25.                        'Actually you don't need to pass the 0, but AmigaBasic seems to want something...
  26.  
  27.  IF FileIO = 0 THEN GOTO CloseUp1 '0 means that you don't have a FileIO.
  28.   
  29.  'Set the title that will displayed in the FileIO window. This can be changed
  30.  'for each call.
  31.  
  32.  Zero$=""
  33.  WindowTitle$ = "FileIO Example: MULTIPLE_SELECT"
  34.  WindowTitle$=WindowTitle$+Zero$    'for some reason, AmigaBasic adds a quote char
  35.                                     'to the end of strings. This gets rid of it.
  36.                                     'If you comment out this line and look at the
  37.                                     'title bar of the requester window, you'll see it.
  38.  POKEL FileIO+244,SADD(WindowTitle$)
  39.  
  40.  'Set the fore pen, back pen, and draw mode for title bar routines to some
  41.  'defaults.
  42.  
  43.  POKE  FileIO+261,1  'JAM2 DrawMode
  44.  POKE  FileIO+262,1  'PenA = Color1
  45.  POKE  FileIO+263,0  'PenB = Color0
  46.  
  47.  DIM message$(196)  'A place large enough to store user's chosen string
  48.     
  49. 'Enable the SPECIAL_REQ feature of the FileIO
  50.   value=PEEK(FileIO+0)
  51.   value=value+128          'Only do this ONCE!!! To turn off SPECIAL_REQ later, subtract 128
  52.   POKE  FileIO+0,value     'Turn on SPECIAL_REQ
  53.  
  54. 'Enable the MULTIPLE_SELECT feature of the FileIO
  55.   value=PEEK(FileIO+1)
  56.   value=value+64
  57.   POKE  FileIO+1,value
  58.   
  59.   'Let's make up a list to display. We'll display strings of "One" to "Ten"
  60.   'with the IDs being the respective values. First, we should  call
  61.   'NewEntryList as that will free any previous list for this FileIO.
  62.  
  63.   CALL NewEntryList(FileIO)
  64.   FOR i = 1 TO 10
  65.   READ message$
  66.   message$=message$+Zero$
  67.   Result=AddEntry(i,SADD(message$),FileIO)
  68.   IF Result<0 THEN GOTO CloseUp   'Couldn't add the string to the list.
  69.                                   'Actually you could continue on after
  70.                                   'informing the user that "something"
  71.                                   'will be missing from the list.
  72.   NEXT i
  73.     
  74. Again:  
  75.  Result=DoFileIOWindow(FileIO,0)  'do the FileIO selection on WB screen  
  76.  
  77.  IF Result <> -1 THEN GOTO CheckError    '-1 means the user selected CANCEL.
  78.  message$ = "User selected CANCEL."+CHR$(0)
  79.  CALL AutoMessageLen(SADD(message$),WINDOW(7),21) '21 is the number of chars in Message$ not counting the CHR$(0)
  80.  GOTO chkmore
  81.  
  82. CheckError:
  83.  '0 means the FileIO window couldn't open due (probably due to lack of mem).
  84.  'Too bad! You'll have to get the filename some other way. Maybe an INPUT statement?
  85.  IF Result <> 0 THEN GOTO InUse              
  86.  'Message number 0 in the FileIO lib says "Out of memory for this operation" 
  87.  Result=AutoFileMessage(0,WINDOW(7))
  88.  GOTO chkmore
  89.  
  90. InUse:
  91.   '-2 means somebody else is using the requester.
  92.  IF Result <> -2 THEN GOTO GotString
  93.  message$ = "Requester in use."+CHR$(0)
  94.  CALL AutoMessageLen(SADD(message$),WINDOW(7),17)
  95.  GOTO chkmore 
  96.  
  97. GotString:       'We got selections from the user!
  98.   'Now, all the entries selected the FileIO's FileList have their SELECTED BIT
  99.   'set. We use RetrieveEntry to extract each selected string one at a time
  100.   'until there are no more. Note that all of these strings will be in the list
  101.   '(because that's what we're examining). It's also possible that the user
  102.   'could have typed in a string not in the list. We can either ignore this
  103.   'if not relevant, or we could get that string from the FileIO's Filename
  104.   'field. The FileSize will be -1 if that string was not in the list. Otherwise,
  105.   'it's one of the strings that we're going to get from the list anyway.
  106.   'Here, I ignore the user typing in a non-existant string.
  107.  
  108.  CLS
  109.  LOCATE 7,1
  110.  
  111.  fileEntryPtr=0  'initially 0
  112.  
  113. MoreSelect:
  114.   entry = RetrieveEntry(VARPTR(fileEntryPtr),FileIO)  'This returns a FileEntry structure
  115.   IF entry = 0 THEN GOTO chkmore        'Was there another one?
  116.   ptr = PEEKL(entry+8)  'get the Entry structure from the FileEntry
  117.  
  118.  'copy the string to message$  
  119.  message$ = ""
  120.  FOR i = 0 TO 193       'there can be a total of 191 chars in the string
  121.     value = PEEK(ptr+5+i)
  122.     IF value = 0 THEN GOTO GetID
  123.     char$ = CHR$(value)
  124.     message$ = message$+char$    
  125.  NEXT i 
  126.  
  127.   'get the ID
  128. GetID:
  129.  ID=PEEKL(ptr)
  130.  
  131.  'Print out the chosen string and its ID
  132.  PRINT "The chosen string is ",message$
  133.  PRINT "The ID is ",ID
  134.  
  135.  'Get the next selected one if there is one
  136.  GOTO MoreSelect
  137.  
  138. chkmore: 
  139.  message$  = "This has been a test of the FileIO library." + CHR$(0)
  140.  message2$ = "Do you want to retry?" + CHR$(0)
  141.  boolean=AutoPrompt3(SADD(message$),SADD(message2$),0,WINDOW(7))
  142.  CLS
  143.  IF boolean = 1 THEN GOTO Again
  144.  
  145.  'Note how the lib automatically spaces these messages symmetrically
  146.  
  147.  message$ = "Example program and asm lib by Jeff Glatt" + CHR$(0)
  148.  message2$ = "(dissidents)" + CHR$(0)
  149.  Message3$ = "Based on an example by RJ Mical" + CHR$(0)
  150.  boolean=AutoPrompt3(SADD(message$),SADD(message2$),SADD(Message3$),WINDOW(7))  
  151.  
  152. CloseUp: 
  153.  CALL ResetTitle(FileIO,WINDOW(7)) 'Maybe we changed it for the error msgs.
  154.  
  155. CloseUp1:
  156.  CALL ReleaseFileIO(FileIO)        'Free the FileIO structure
  157.  LIBRARY CLOSE
  158.  END
  159.  DATA  "This is One"
  160.  DATA  "Two"
  161.  DATA  "Three"
  162.  DATA  "Four"
  163.  DATA  "Five"
  164.  DATA  "Six"
  165.  DATA  "Seven"
  166.  DATA  "Eight"
  167.  DATA  "Nine"
  168.  DATA  "Ten"
  169.