In order for this site to work correctly, and for us to improve the site, we need to store a small file (called a cookie) on your computer.
By continuing to use this website, you agree to our cookies and privacy policy.
Home page Home page Home page Home page
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel

Readers Clinic - Locating at a specific MV in an AMV Group

Mike Nourse of JM2 Systems Inc recently posed the following complicated query - " I have a single valued date prompt preceding an AMV group. The AMV group has a controlling date mv and three associated money mvs. My goal is to have the user enter the date in the single valued prompt and locate it or where it ought to be in the controlling AMV. Once a position is found, start to display the AMV group at that mv position. The group data will already be sorted in descending date order."

This task actually turned out to be more complicated than it at first appears. Referring back to WC_AMV_VARS% (Vol 2 Iss 9 Page 10) it seemed that all that needed to be done was to locate the correct position within the array and then set WC_AMV_VARS%< WC_CURR_AMV_GROUP%, AMV_DISPLAY$ > to this position, and set WC_AMV_ACTION% to 4 for "changed". However whenever this was done, the system automatically overwrote the AMV_DISPLAY$ setting, putting it back to 1 thus foiling the attempt. What was required was a way to force an AMV reset without resetting AMV_DISPLAY$. The code following achieves the result. The paragraph following the code explains how it works.

0001    Subroutine  LocateInGroup
0002    /*
0003      Author   AMcA
0004      Date     June 92
0005      Purpose  This routine is designed to be called from the collector at the
0006               preprompt of a controlling MV of an AMV group. It takes the
0007               value of @Record<1> (change this for your requirements) and
0008               locates it in the current field in @Record, and realigns the
0009               entire grouped display at that point.
0010    */
0012    $Insert Include, Window_Common%
0013    $Insert Include, LCPositions
0014    $Insert Include, Window.Constants
0015    Value = @Record<1>
0017    /*
0018       Check the prompt register to see if  we have already done this value if
0019       so don't move. This prevents an infinite loop occasioned by using RESET
0020       on a preprompt. The disadvantage of this is that the MVs will only
0021       relocate the first time the value is changed.
0022    */
0023    If WC_SI%< PReg1 > = Value Then
0024      Null
0025    End Else
0026      CurrentField = @Record< WC_SI%< FNO > >
0027      Locate Value In CurrentField By "DR" Using @VM Setting Pos Else Null
0028      WC_SI%< PReg1 > = Value
0029      WC_MV% = Pos
0030      For X = 1 To WC_Amv_Vars%< WC_Curr_Amv_Group%, Amv.Width$ >
0031       Field = WC_W%( WC_Amv%< WC_Curr_Amv_Group%, X> )< FNO >
0032       * Add a dummy line
0033       @Record = Insert(@Record, Field, Pos, 0, "*")
0034      Next
0035      WC_Amv_Action% = Amv.Delete$
0036      * Set line to start display at
0037      WC_Amv_Vars%< WC_Curr_Amv_Group%, Amv.Display$ > = Pos
0038      * Tell window processor about the dummy line
0039      WC_Amv_Vars%< WC_Curr_Amv_Group%, Amv.Depth$> =
0040                   WC_Amv_Vars%< WC_Curr_Amv_Group%, Amv.Depth$> + 1
0041      WC_Reset% = Reset.Prompt$
0042    End
0043    Return

When in an associated MVed group, deleting a line leaves the cursor at the current MV position regardless of how far down the AMV group it is. Thus the answer was to set the correct position in MV and AMV_DISPLAY and to force a non-destructive delete. The latter might seem to be a non-sequitur but can be achieved by inserting a dummy row specifically for it to be deleted.

(Volume 4, Issue 3, Pages 6,7)
Pixel Footer R1 C1 Pixel