home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d4xx / d463 / fileio.lha / FileIO / FileIO.lzh / BASIC / BasicList (.txt) < prev    next >
AmigaBASIC Source Code  |  1991-02-08  |  6KB  |  153 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 AddEntry() 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: SPECIAL_REQ"
  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.   'Let's make up a list to display. We'll display strings of "One" to "Ten"
  55.   'with the IDs being the respective values. First, we should  call
  56.   'NewEntryList as that will free any previous list for this FileIO.
  57.  
  58.   CALL NewEntryList(FileIO)
  59.   FOR i = 1 TO 10
  60.   READ message$
  61.   message$=message$+Zero$
  62.   Result=AddEntry(i,SADD(message$),FileIO)
  63.   IF Result<0 THEN GOTO CloseUp   'Couldn't add the string to the list.
  64.                                   'Actually you could continue on after
  65.                                   'informing the user that "something"
  66.                                   'will be missing from the list.
  67.   NEXT i
  68.   
  69.   'It's OK to set the Text that appears in the custom gadget, but don't try
  70.   'to install a custom routine. Not in AmigaBasic you don't!
  71.   
  72.   GadgText$="Basic Test"
  73.   GadgText$=GadgText$+Zero$
  74.   POKEL FileIO+208,SADD(GadgText$)  
  75.   
  76. Again:  
  77.  Result=DoFileIOWindow(FileIO,0)  'do the FileIO selection on WB screen  
  78.  
  79.  IF Result <> -1 THEN GOTO CheckError    '-1 means the user selected CANCEL.
  80.  message$ = "User selected CANCEL."+CHR$(0)
  81.  CALL AutoMessageLen(SADD(message$),WINDOW(7),21) '21 is the number of chars in Message$ not counting the CHR$(0)
  82.  GOTO chkmore
  83.  
  84. CheckError:
  85.  '0 means the FileIO window couldn't open due (probably due to lack of mem).
  86.  'Too bad! You'll have to get the filename some other way. Maybe an INPUT statement?
  87.  IF Result <> 0 THEN GOTO InUse              
  88.  'Message number 0 in the FileIO lib says "Out of memory for this operation" 
  89.  Result=AutoFileMessage(0,WINDOW(7))
  90.  GOTO chkmore
  91.  
  92. InUse:
  93.   '-2 means somebody else is using the requester.
  94.  IF Result <> -2 THEN GOTO GotString
  95.  message$ = "Requester in use."+CHR$(0)
  96.  CALL AutoMessageLen(SADD(message$),WINDOW(7),17)
  97.  GOTO chkmore 
  98.  
  99. GotString:       'We got a selection from the user!
  100.   'Now, the FileIO's Filename buffer has the chosen string, and the FileIO's
  101.   'FileSize field is the ID for that string. Let's copy these to AmigaBasic
  102.   'variables.
  103.  
  104.  message$ = ""
  105.  FOR i = 0 TO 60
  106.     value = PEEK(FileIO+2+i)
  107.     IF value = 0 THEN GOTO GetID
  108.     char$ = CHR$(value)
  109.     message$ = message$+char$    
  110.  NEXT i 
  111.  
  112. GetID:
  113.  ID=PEEKL(FileIO+240)
  114.  
  115.  'Print out the chosen string and its ID
  116.  CLS
  117.  LOCATE 16,1
  118.  PRINT "The chosen string is ",message$
  119.  PRINT "The ID is ",ID
  120.  IF ID = -1 THEN PRINT "This string is not in the list."
  121.  
  122. chkmore: 
  123.  message$  = "This has been a test of the FileIO library." + CHR$(0)
  124.  message2$ = "Do you want to retry?" + CHR$(0)
  125.  boolean=AutoPrompt3(SADD(message$),SADD(message2$),0,WINDOW(7))
  126.  CLS
  127.  IF boolean = 1 THEN GOTO Again
  128.  
  129.  'Note how the lib automatically spaces these messages symmetrically
  130.  
  131.  message$ = "Example program and asm lib by Jeff Glatt" + CHR$(0)
  132.  message2$ = "(dissidents)" + CHR$(0)
  133.  Message3$ = "Based on an example by RJ Mical" + CHR$(0)
  134.  boolean=AutoPrompt3(SADD(message$),SADD(message2$),SADD(Message3$),WINDOW(7))  
  135.  
  136. CloseUp: 
  137.  CALL ResetTitle(FileIO,WINDOW(7)) 'Maybe we changed it for the error msgs.
  138.  
  139. CloseUp1:
  140.  CALL ReleaseFileIO(FileIO)        'Free the FileIO structure
  141.  LIBRARY CLOSE
  142.  END
  143.  DATA  "This is One"
  144.  DATA  "Two"
  145.  DATA  "Three"
  146.  DATA  "Four"
  147.  DATA  "Five"
  148.  DATA  "Six"
  149.  DATA  "Seven"
  150.  DATA  "Eight"
  151.  DATA  "Nine"
  152.  DATA  "Ten"
  153.