Q: I have started programming my interactive programs with cursor-sensitive searches. If the user presses a function key to perform a search, I calculate the location of the cursor. If it falls within a hard-coded range, I present the user with the requested search. I want to soft-code that range from the display file. I should be able to match the cursor position to the field location and present the user with the desired search. Is there a way to retrieve the location of a field within a display file (other than reading the display file source)?
A: There's an easy way to accomplish this. Use the DDS Return Cursor Location (RTNCSRLOC) record-level keyword in your display file. It returns the name of the field that the cursor is on. This method has some advantages over using hard-coded screen coordinates. It means that if you move a field in a display file from one location on the screen to another, you don't have to worry about changing the program which uses that display file.
The return cursor location has two required parameters as well as an optional third parameter. For an example of how to use this keyword look at the four lines of code in 3. The two required parameters, (cursor-record and cursor-field), must be defined as 10-character hidden fields. The cursor-record variable returns the name of the record format and the cursor-field variable returns the name of the field where the cursor is located. The third parameter (cursor-position) is optional and, if used, must be defined as a four-position, signed-numeric, hidden field. This field returns the relative position within the field where the cursor is located.
The return cursor location has two required parameters as well as an optional third parameter. For an example of how to use this keyword look at the four lines of code in Figure 3. The two required parameters, (cursor-record and cursor-field), must be defined as 10-character hidden fields. The cursor-record variable returns the name of the record format and the cursor-field variable returns the name of the field where the cursor is located. The third parameter (cursor-position) is optional and, if used, must be defined as a four-position, signed-numeric, hidden field. This field returns the relative position within the field where the cursor is located.
In your program, just test the value of the cursor-field variable. If it matches a field for which the user can perform a search, then present the search results. If it doesn't, you might want to display a message which says something like, "Search not valid for cursor location." Using this technique, you can code cursor-sensitive searches within your programs without hardcoding screen coordinates.
Cursor-sensitive Searches
Figure 3 DDS for RTNCSRLOC Keyword
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A RTNCSRLOC(&RCD &FLD &POS) A RCD 10A H A FLD 10A H A POS 4S 0H
LATEST COMMENTS
MC Press Online