Purpose
Allow the user to select multiple values

Solution
We use a table with row selection.

Example
When goods are received, damage should be classified according to predefined codes. We store the possible damage codes with the damage texts in a text file "damagecodes.txt" in the script directory:

 

We offer the user the list of damage codes as a table in which he can select several entries by selecting rows. To transfer the selected entries to a string field, we use a separate button below the table. In our example, this only fills a separate variable, which is also displayed as "List of damages". Depending on the application, the value list instead could  be transferred to an existing comment field in the transaction.

GuiXT Script:

// new transaction? then read the damage codes from the text file
if not V[mytransactionid=&V[_transactionid]]
  Set V[mytransactionid] "&V[_transactionid]"
 
  // create code table
  CreateTable V[codetable] code text
 
 
// reset previous selection
  Clear V[codetable.stat.*]
 
Clear V[codelist]
 
 
  // load content from damage code file
  CopyText fromFile="damagecodes.txt" toText="damagecodes"
 
CopyText fromText="damagecodes" toTable=V[codetable] delimiter=";"
 
endif


// display selected codes in list form
InputField  (2,1)  "List of damages"  (2,18) size=35 _

      name="codelist" -readOnly

// Let the user select multiple values
Table  (4,1)  (14,53) title="Damage code selection" _

     name="codetable"  -rowSelection
Column "Code" -readOnly  size=8 name="code" table="codetable"
Column "Text" -readOnly  size=60 name="text" table="codetable"

// selected codes to list field
PushButton  (15,1) "Transfer damage codes to the list"  _
         process="transfer_codes.txt"

// button to remove all selections
PushButton  (15,47)  "@4D@Clear" process="clear_codes.txt"

 

InputScript "transfer_codes.txt":

// reset list

Clear V[codelist]

// row index

Set V[k] 0

// build up list field

label next_row

if V[k<&V[codetable.rowcount]]

  Set V[k] &V[k] + 1

  if V[codetable.stat.rowselection.&V[k]=X]

    if V[codelist]

      Set V[codelist] "&V[codelist],"

    endif

   

    Set V[codelist] "&V[codelist]&V[codetable.code.&V[k]]"

   

  endif

 

  goto next_row

 

endif

Return

InputScript "clear_codes.txt":

// clear code selection

Clear V[codetable.stat.rowselection.*]

Clear V[codelist]

Return

.zip file with sample scripts

 

Components GuiXT  + InputAssistant