home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / fiasco_2.1 / arexx / converttolistview.frx < prev    next >
Text File  |  1997-10-06  |  4KB  |  184 lines

  1. /* ConvertToListview.frx
  2.  * Converts a certain number of simple fields to one listview field
  3.  * Copyright © 1997 Nils Bandener
  4.  * $VER: ConvertToListview_frx 6.2 (6.10.97)
  5.  */
  6.  
  7. /* Usage:
  8.  *
  9.  * The IDs of the simple fields must end with numbers, counting from
  10.  * 1 to a given value. The listview field, to which the fields will
  11.  * be converted to, must be already created before executing this
  12.  * script.
  13.  *
  14.  * Call:
  15.  *
  16.  * rx ConvertToListview.rexx <SimpleID> <Number> <ListviewID>
  17.  *
  18.  * SimpleID:   The ID of the simple fields. If your simple fields
  19.  *             are named "Field_1", "Field_2", "Field_3", etc.,
  20.  *             you have to give "Field_" here.
  21.  * Number:     The number of simple fields. If you have fields
  22.  *             from "Field_1" to "Field_25", you have to give
  23.  *             25 here.
  24.  * ListviewID: The ID of the listview, in which the data will be
  25.  *             put.
  26.  */
  27.  
  28. Parse Arg SimpleID FieldNum ListviewID
  29. Options Results
  30.  
  31. scriptname = "Convert To Listview"
  32.  
  33. Options Results
  34.  
  35. /*
  36.  *  If not called from Fiasco, try to address the active
  37.  *  Fiasco project
  38.  */
  39.  
  40. if ~abbrev(address(), "FIASCO.") then
  41. do
  42.     ports = show("Ports")
  43.  
  44.     do i = 1 to words(ports)
  45.  
  46.         if abbrev(word(ports, i), "FIASCO.") then
  47.         do
  48.             Address Value word(ports, i)
  49.  
  50.             GetAttr Project Name Active ARexx
  51.  
  52.             Address Value Result
  53.  
  54.             break
  55.         end
  56.     end
  57. end
  58.  
  59. fiasco_port = address()
  60.  
  61. Signal on Syntax
  62. Signal on Halt
  63. Signal on Break_C
  64. Signal on Failure
  65.  
  66. LockGUI
  67.  
  68. if SimpleID = "" then
  69. do
  70.     RequestString '"" Text "Please enter the ID of the*nsimple fields to be converted:*n(If these fields are named Field_1, Field_2, ..., enter Field_)"'
  71.  
  72.     if rc ~= 0 then call bail_out
  73.  
  74.     SimpleID = Result
  75.  
  76. end
  77.  
  78. if FieldNum = "" | FieldNum = 0 then
  79. do
  80.  
  81.     RequestNumber '"1" Text "Please enter the number of*nsimple fields with the ID*n' || SimpleID || '"'
  82.  
  83.     if rc ~= 0 then call bail_out
  84.  
  85.     FieldNum = Result
  86.  
  87. end
  88.  
  89. if ListviewID = "" then
  90. do
  91.  
  92.     RequestField 'Text "Please select the listview field,*ninto which the data will be put"'
  93.  
  94.     if rc ~= 0 then call bail_out
  95.  
  96.     ListviewID = Result
  97.  
  98. end
  99.  
  100. CountRecords Var recnum
  101.  
  102. /*
  103.  *  Go through all records
  104.  */
  105.  
  106. do i = 1 to recnum
  107.  
  108.     do k = 1 to fieldnum
  109.  
  110.         GetField '"' || SimpleID || k || '"' Record i
  111.         cont = result
  112.  
  113.         /*
  114.          *  Only add a new entry, if everything is
  115.          *  Ok and cont is not empty
  116.          */
  117.  
  118.         if rc = 0 & cont ~= "" then
  119.         do
  120.             AddLVFieldEntry '"' || ListviewID || '"' Record i
  121.  
  122.             /*
  123.              *  Read the number of entries
  124.              *  in the listview field
  125.              */
  126.  
  127.             GetField '"' || ListviewID || '"' Record i ListEntryCount Var entnum
  128.  
  129.             SetField '"' || ListviewID || '"' Record i ListEntry entnum cont
  130.  
  131.         end
  132.  
  133.     end
  134.  
  135. end
  136.  
  137. bail_out:
  138.  
  139. Address Value fiasco_port
  140.  
  141. UnlockGUI
  142. ResetStatus
  143.  
  144. exit
  145.  
  146. syntax:
  147. failure:
  148.  
  149. if show("Ports", fiasco_port) then
  150. do
  151.     Interpret Address fiasco_port
  152.  
  153.     RequestChoice '"Error ' || rc || ' in line ' || sigl || ':*n' || errortext(rc) || '" "Cancel" Title "' || scriptname || '"'
  154. end
  155. else
  156. do
  157.     say "Error" rc "in line" sigl ":" errortext(rc)
  158.     say "Enter to continue"
  159.     pull dummy
  160. end
  161.  
  162. call bail_out
  163.  
  164. halt:
  165. break_c:
  166.  
  167. if show("Ports", fiasco_port) then
  168. do
  169.     Interpret Address fiasco_port
  170.  
  171.     RequestChoice '"Script Abort Requested" "Abort Script" Title "' || scriptname || '"'
  172.  
  173.     if result = 0 then return
  174. end
  175. else
  176. do
  177.     say "*** Break"
  178.     say "Enter to continue"
  179.     pull dummy
  180. end
  181.  
  182. call bail_out
  183.  
  184.