home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 326.lha / requester.library_v1.3 / BasicList (.txt) < prev    next >
AmigaBASIC Source Code  |  1989-12-30  |  6KB  |  159 lines

  1.  CLS
  2.  LOCATE 1,8
  3.  PRINT "Demo AmigaBasic program using the FileIO requester library."
  4.  LOCATE 2,11
  5.  PRINT "Literally hacked together by Jeff Glatt (dissidents)"
  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 in the FileIO lib.
  16.  DECLARE FUNCTION GetFullPathname() LIBRARY 'Other functions in the lib do
  17.  DECLARE FUNCTION GetFileIO() LIBRARY       'not return values, and so do not
  18.  DECLARE FUNCTION AutoFileMessage() LIBRARY 'need declaring
  19.  DECLARE FUNCTION AutoPrompt3() LIBRARY
  20.  DECLARE FUNCTION TypeFilename() LIBRARY
  21.  DECLARE FUNCTION UserEntry() LIBRARY
  22.  DECLARE FUNCTION PromptUserEntry() LIBRARY
  23.  DECLARE FUNCTION GetRawkey() LIBRARY
  24.  DECLARE FUNCTION DecodeRawkey() LIBRARY
  25.  DECLARE FUNCTION AddEntry() LIBRARY
  26.  DECLARE FUNCTION IsEntryThere() LIBRARY
  27.  
  28.  'For SPECIAL_REQ, we don't need a buffer for the pathname.
  29.   
  30.  FileIO=GetFileIO(0)  'Get the address of the FileIO structure
  31.                        'Actually you don't need to pass the 0, but AmigaBasic seems to want something...
  32.  
  33.  IF FileIO = 0 THEN GOTO CloseUp1 '0 means that you don't have a FileIO.
  34.   
  35.  'Set the title that will displayed in the FileIO window. This can be changed
  36.  'for each call.
  37.  
  38.  Zero$=""
  39.  WindowTitle$ = "FileIO Example: SPECIAL_REQ"
  40.  WindowTitle$=WindowTitle$+Zero$    'for some reason, AmigaBasic adds a quote char
  41.                                     'to the end of strings. This gets rid of it.
  42.                                     'If you comment out this line and look at the
  43.                                     'title bar of the requester window, you'll see it.
  44.  POKEL FileIO+244,SADD(WindowTitle$)
  45.  
  46.  'Set the fore pen, back pen, and draw mode for title bar routines to some
  47.  'defaults.
  48.  
  49.  POKE  FileIO+261,1  'JAM2 DrawMode
  50.  POKE  FileIO+262,1  'PenA = Color1
  51.  POKE  FileIO+263,0  'PenB = Color0
  52.  
  53.  DIM message$(60)  'A place large enough to store user's chosen string
  54.     
  55. 'Enable the SPECIAL_REQ feature of the FileIO
  56.   value=PEEK(FileIO+0)
  57.   value=value+128          'Only do this ONCE!!! To turn off SPECIAL_REQ later, subtract 128
  58.   POKE  FileIO+0,value     'Turn on SPECIAL_REQ
  59.   
  60.   'Let's make up a list to display. We'll display strings of "One" to "Ten"
  61.   'with the IDs being the respective values. First, we should  call
  62.   'NewEntryList as that will free any previous list for this FileIO.
  63.  
  64.   CALL NewEntryList(FileIO)
  65.   FOR i = 1 TO 10
  66.   READ message$
  67.   message$=message$+Zero$
  68.   Result=AddEntry(i,SADD(message$),FileIO)
  69.   IF Result<0 THEN GOTO CloseUp   'Couldn't add the string to the list.
  70.                                   'Actually you could continue on after
  71.                                   'informing the user that "something"
  72.                                   'will be missing from the list.
  73.   NEXT i
  74.   
  75.   'It's OK to set the Text that appears in the custom gadget, but don't try
  76.   'to install a custom routine. Not in AmigaBasic you don't!
  77.   
  78.   GadgText$="Basic Test"
  79.   GadgText$=GadgText$+Zero$
  80.   POKEL FileIO+208,SADD(GadgText$)  
  81.   
  82. Again:  
  83.  Result=DoFileIOWindow(FileIO,0)  'do the FileIO selection on WB screen  
  84.  
  85.  IF Result <> -1 THEN GOTO CheckError    '-1 means the user selected CANCEL.
  86.  message$ = "User selected CANCEL."+CHR$(0)
  87.  CALL AutoMessageLen(SADD(message$),WINDOW(7),21) '21 is the number of chars in Message$ not counting the CHR$(0)
  88.  GOTO chkmore
  89.  
  90. CheckError:
  91.  '0 means the FileIO window couldn't open due (probably due to lack of mem).
  92.  'Too bad! You'll have to get the filename some other way. Maybe an INPUT statement?
  93.  IF Result <> 0 THEN GOTO InUse              
  94.  'Message number 0 in the FileIO lib says "Out of memory for this operation" 
  95.  Result=AutoFileMessage(0,WINDOW(7))
  96.  GOTO chkmore
  97.  
  98. InUse:
  99.   '-2 means somebody else is using the requester.
  100.  IF Result <> -2 THEN GOTO GotString
  101.  message$ = "Requester in use."+CHR$(0)
  102.  CALL AutoMessageLen(SADD(message$),WINDOW(7),17)
  103.  GOTO chkmore 
  104.  
  105. GotString:       'We got a selection from the user!
  106.   'Now, the FileIO's Filename buffer has the chosen string, and the FileIO's
  107.   'FileSize field is the ID for that string. Let's copy these to AmigaBasic
  108.   'variables.
  109.  
  110.  message$ = ""
  111.  FOR i = 0 TO 60
  112.     value = PEEK(FileIO+2+i)
  113.     IF value = 0 THEN GOTO GetID
  114.     char$ = CHR$(value)
  115.     message$ = message$+char$    
  116.  NEXT i 
  117.  
  118. GetID:
  119.  ID=PEEKL(FileIO+240)
  120.  
  121.  'Print out the chosen string and its ID
  122.  CLS
  123.  LOCATE 16,1
  124.  PRINT "The chosen string is ",message$
  125.  PRINT "The ID is ",ID
  126.  IF ID = -1 THEN PRINT "This string is not in the list."
  127.  
  128. chkmore: 
  129.  message$  = "This has been a test of the FileIO library." + CHR$(0)
  130.  message2$ = "Do you want to retry?" + CHR$(0)
  131.  boolean=AutoPrompt3(SADD(message$),SADD(message2$),0,WINDOW(7))
  132.  CLS
  133.  IF boolean = 1 THEN GOTO Again
  134.  
  135.  'Note how the lib automatically spaces these messages symmetrically
  136.  
  137.  message$ = "Example program and asm lib by Jeff Glatt" + CHR$(0)
  138.  message2$ = "(dissidents)" + CHR$(0)
  139.  Message3$ = "Based on an example by RJ Mical" + CHR$(0)
  140.  boolean=AutoPrompt3(SADD(message$),SADD(message2$),SADD(Message3$),WINDOW(7))  
  141.  
  142. CloseUp: 
  143.  CALL ResetTitle(FileIO,WINDOW(7)) 'Maybe we changed it for the error msgs.
  144.  
  145. CloseUp1:
  146.  CALL ReleaseFileIO(FileIO)        'Free the FileIO structure
  147.  LIBRARY CLOSE
  148.  END
  149.  DATA  "This is One"
  150.  DATA  "Two"
  151.  DATA  "Three"
  152.  DATA  "Four"
  153.  DATA  "Five"
  154.  DATA  "Six"
  155.  DATA  "Seven"
  156.  DATA  "Eight"
  157.  DATA  "Nine"
  158.  DATA  "Ten"
  159.