routine ANIMALS.CTL given FIELD.ID, FORM yielding STATUS
''
''    AUTHOR: Steve Bailey
''    CREATED: 9-8-93
''    DESCRIPTION:
''      Control routine for the dialog box containing a list of animal names.
''

    define FIELD.ID as a text variable
    define FORM, TBOX.PTR, LBOX.PTR as pointer variables
    define STATUS, I, SELECTED as integer variables
    define ITEMS, NEW.ITEMS as 1-dim text array

    let TBOX.PTR = DFIELD.F("ANIMAL", FORM)
    let LBOX.PTR = DFIELD.F("ANIMALS", FORM)
    let ITEMS(*) = DARY.A(LBOX.PTR)

      '' see which control on the dialog was last selected
    select case FIELD.ID
        '' initialize call automatically by accept.f
      case "INITIALIZE", "REVERT"
        reserve NEW.ITEMS(*) as 8
        let NEW.ITEMS(1) = "ant" let NEW.ITEMS(2) = "bee" 
        let NEW.ITEMS(3) = "cat" let NEW.ITEMS(4) = "dog" 
        let NEW.ITEMS(5) = "elk" let NEW.ITEMS(6) = "fox"
        let NEW.ITEMS(7) = "gnu" let NEW.ITEMS(8) = "hen"
        let DARY.A(LBOX.PTR) = NEW.ITEMS(*)
        if FIELD.ID eq "REVERT"
            display LBOX.PTR
        always

        '' list box was selected
      case "ANIMALS" 
        let DTVAL.A(TBOX.PTR) = DTVAL.A(LBOX.PTR)
        display TBOX.PTR

        '' text box was selected
      case "ANIMAL"
          '' if user hits return in the text box, add its contents to list box
        reserve NEW.ITEMS(*) as DIM.F(ITEMS(*)) + 1
        let NEW.ITEMS(1) = DTVAL.A(TBOX.PTR)

          '' copy elements of the existing items array to new array
        for I = 1 to DIM.F(ITEMS(*)) do
            let NEW.ITEMS(I+1) = ITEMS(I)
        loop

        let DARY.A(LBOX.PTR) = NEW.ITEMS(*)
        release ITEMS(*)
        display LBOX.PTR

        '' print button was selected
      case "PRINT"
        write "The following animals were selected: " as T * 

          '' write out all the list items that are currently selected
        for I = 1 TO DIM.F(ITEMS(*)) do
            call LISTBOX.SELECTED.R(LBOX.PTR, I) yielding SELECTED 
            if SELECTED ne 0
                write ITEMS(I) as T *, ", "
            always
        loop
        write as /

          '' deselect all list items
        let DDVAL.A(LBOX.PTR) = 0
        display LBOX.PTR

        '' quit button was selected
      case "QUIT"
        let STATUS = 1

      default
    endselect
end
