Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying specific elements of a program array in a screen array. 1

Status
Not open for further replies.

asdITGuy

Programmer
Jan 11, 2007
1
0
0
US
Hi everyone,
I'm having lots of trouble with this one (I'm new to Informix 4gl).

Situation.
There is a screen with 2 screen arrays in the middle display some budget information (group / $amount added) and (group / $amount subtracted).

Steps leading to the problem.
1. I have a screen array loaded by a program array.
2. I select a row in either of the arrays.
3. I delete the row (F2).

Problem.
The index that becomes selected after the deletion is the very 1st one in the program array. This is a big problem when you want to delete rows say... 100 lines down, as it keeps sending you back up to the 1st row after each deletion.. forcing you to scroll down every time.

Question.
How can I keep the elements of the program array around the one I was deleting as the ones being currently displayed in the screen arrays?

There doesn't seem to be a function for setting the "view" of the screen arrays to any particular elements in the program array.

Thanks!
 
In the older versions of Informix 4GL, what you described - deleting a row and sending the cursor back to row 1 - actually was an issue. I'm using 7.3UC7 and it appears to work. Perhaps you are using an older version.

In the old days, I dreamed up a kludge to get around this problem: Create a dummy_char NOENTRY on the screen field. When you press delete, set variable cur_ptr to the current row numer, exit input and re-enter the input array statement. In the BEFORE ROW section send the cursor to the noentry field and decreate the row number until cur_ptr = 0 and that puts the user at the point was delete was executed.

This is defintely a kludge. If you have a lot of rows, you'll see screen flicker. Sorry, can't help it.

Let's look at an example: Given this test table:
Code:
create table ttest      
  (
    col1 char(10),
    col2 char(10)
  );

and this screen form xx_ttest.per (note the noentry column):
Code:
database mytest
screen
{
   col 1        col2
[f000       |f001        |e]
[f000       |f001        |e]
[f000       |f001        |e]
[f000       |f001        |e]
[f000       |f001        |e]
}
end
tables
ttest
attributes
f000 = FORMONLY.col1 TYPE CHAR;
f001 = FORMONLY.col2 TYPE CHAR;
e    = FORMONLY.dummy_char TYPE CHAR, NOENTRY;
INSTRUCTIONS
DELIMITERS " "
SCREEN RECORD sa_ttest [5] (col1, col2, dummy_char)
end

Here is the test 4GL code. Let me know if you have any questions:

Code:
DATABASE mytest

MAIN

   DEFINE 
      p_ttest RECORD LIKE ttest.*,
      pa_ttest ARRAY[20] OF RECORD
         col1 LIKE ttest.col1,
         col2 LIKE ttest.col2,
         dummy_char CHAR(1)
      END RECORD,
      exit_flag,i SMALLINT,
      cur_ptr SMALLINT,
      curr_pa, curr_sa, cur_row SMALLINT

   DEFER INTERRUPT
   WHENEVER ERROR CONTINUE

   INITIALIZE pa_ttest[1].* TO NULL
   FOR i = 2 TO 20
      LET pa_ttest[i].* = pa_ttest[1].*
   END FOR

   DECLARE open_eds CURSOR FOR
      SELECT * FROM ttest
   LET i = 0
   FOREACH open_eds INTO p_ttest.*
      LET i = i + 1
      LET pa_ttest[i].col1 = p_ttest.col1
      LET pa_ttest[i].col2 = p_ttest.col2
   END FOREACH

   OPEN WINDOW w_ttest AT 3,3 WITH FORM "xx_ttest"
      ATTRIBUTE (BORDER,FORM LINE 1,MESSAGE LINE last)
      OPTIONS NEXT KEY F32, PREVIOUS KEY F33,ACCEPT KEY CONTROL-B,
         INSERT KEY F34, DELETE KEY F2

   LET exit_flag = FALSE
   LET int_flag = FALSE
   CALL set_count(i)
   WHILE exit_flag = FALSE
      LET exit_flag = TRUE
      INPUT ARRAY pa_ttest WITHOUT DEFAULTS FROM sa_ttest.*

         ON KEY (interrupt)
            LET exit_flag = TRUE
            EXIT INPUT

         BEFORE ROW
            # go to next row until the "deleted row" is reached
            LET curr_pa = ARR_CURR()
            LET curr_sa = SCR_LINE()
            IF cur_ptr > 1
            THEN
               IF curr_pa = cur_row
               THEN
                  LET cur_ptr = 0
                  NEXT FIELD col2
               ELSE
                  LET cur_ptr = cur_ptr -1
                  NEXT FIELD dummy_char
               END IF
            END IF

         AFTER DELETE
            IF curr_pa > 1
            THEN
               LET exit_flag = FALSE
               LET cur_ptr = curr_pa
               LET cur_row = curr_pa - 1
               EXIT INPUT
            END IF

         BEFORE FIELD col1
            LET curr_pa = ARR_CURR()
            LET curr_sa = SCR_LINE()
            IF int_flag = TRUE
            THEN
               IF curr_pa > 1
               THEN
                  LET exit_flag = FALSE
                  LET cur_ptr = curr_pa
                  LET cur_row = curr_pa - 1 # previous row
                  INITIALIZE pa_ttest[curr_pa].* TO NULL
                  EXIT INPUT
               END IF
            END IF

      END INPUT

   END WHILE

   LET exit_flag = FALSE

END MAIN





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top