Copyright 2010 by gINT Software. All rights reserved worldwide.
GR016.TXT

gINT Rules Code Samples - 016

Requires gINT version 8 or later. gINT Logs cannot run gINT Rules but can access the code or the Add-Ins manager. gINT Logs Plus, gINT Professional, and gINT Professional Plus have full access to both.

NOTE:  Code samples are provided free of charge and as-is.  gINT Software makes no claim or warranty as to the accuracy of the samples.  It is the responsibility of the user to ensure that the code performs as it should.  Comments, suggestions, and error reports are appreciated.

Description
===========
!!!!
This rule is the same code run natively in gINT when the Point Sort Field is added to the POINT table and the "gINT Method" property of the field is marked. You would only need to use this rule if you wish to use a different algorithm.
!!!!

This rule populates the GintPointSort field with numbers reflecting the desired sort order for PointIDs. The GintPointSort field can be inserted into the POINT table using the Tables:Point Sort Field menu item in either Input or Data Design:Project Database. The program uses the values in this field to sort PointIDs in the POINT table and all PointID drop downs in Input. This field will also automatically sort your PointIDs at output time.

The code was set up to run on save in the POINT table. If you wish to be able to manually alter the sort values, you can use GRA007 which uses the same core code but will only run when executed from a menu.

This add-in assumes that PointIDs are in the format:
  <Prefix><Number><Suffix>

All of the following will sort properly:
  B-1A
  CPT3
  62
  ABC
  87b

The first example above has all three segments, the second only has the first two segments, the third only the number segment, the fourth only the prefix, and the fifth has the second and third segments.

If your PointIDs are of a different structure, you can modify the code appropriately. Notes on how to do this follow the description below on how the algorithm works.

The algorithm for the add-in is as follows:
1. Walk through each of the PointIDs and parse out the different segments. Store the segments in a structure vector of the following configuration:
Private Type PointIDSegments
  sPrefix As String
  dNumber As Double
  sSuffix As String
  lRowOrg As Long
  lSortOrderOrg As Long
  lGintRecID As Long
End Type

2. Sort the vector of segments by each segment, using the prefix as the primary sort element, the number as the secondary, and the suffix as the tertiary. Therefore, PointIDs without prefixes will sort first.

3. Walk through the data array and insert the segment vector index corresponding to the original PointID.

If your PointIDs conform to a different structure, merely change the PointIDSegments type definition in the Declarations section of the GR016 module to reflect your segmentation and change the parsing and sorting code to work with your segments. The final walk through assignment code will be the same regardless of segmentation.

Revision History
================
14Oct2010:
  Changed the code to properly sort suffix values of the form A#A, where A is a non-number, # is 0-9. E.g.:
    M-1-1 (suffix = -1)
    M-1-1A (suffix = -1A)
    M-1-2 (suffix = -2)
    M-1-3 (suffix = -3)
    ...
    M-1-10 (suffix = -10)

With the previous algorithm the suffix is always sorted as text. In that case the above would sort as:
    M-1-1
    M-1-10
    M-1-1A
    M-1-2
    M-1-3
    ...

The new algorithm checks if the 2nd character of the suffix is 0-9. If so, it parses the suffix into its own prefix/number/suffix structure and formats the number to 20 digits with leading zeros. In the above example, the modified suffixes would look like the following:
    -00000000000000000001
    -00000000000000000001A
    -00000000000000000002
    -00000000000000000003
    ...
    -00000000000000000010

Now the values will sort as follows:
    M-1-1
    M-1-1A
    M-1-2
    M-1-3
    ...
    M-1-10

22Sep2010:
If there was a numeric segment of the PointID that was greater than 2147483647 (2 billion), the code would generate an overflow error. The problem was that the numeric segment was stored in a Long variable and that number is its limit. Changed the variable types that deal with the numeric segment to Double.

20Mar2010:
1. The sort was case sensitive so that "a" sorted after "Z". This was fixed in the HoleSortOrder procedure in the GR016 module. Changed:
    sPointID = gsDataA(iPsPointID, lRow)

to:
    sPointID = UCase$(gsDataA(iPsPointID, lRow))

2. The "sPointID As String" member of the PointIDSegments structure was not used in the code and was removed.
------------------------------------------------

30Jan2008:
There was an error that caused the suffix portion of the PointID not to sort properly. This has been fixed.
------------------------------------------------

19Dec2007:
Initial public upload
*************************************************

INCLUDED FILES:
GR016.GLB:
  Add-Ins:   GR016 - Populates the GintPointSort field on save in the POINT table.

  gINT Rules code modules:
    GR016:  Main
            HoleSave
            HoleSortOrder

    GR016 COMMON PROCEDURES:  InitFieldsFnB
*************************************************

INSTALLATION PROCEDURE:
Copy the files wherever you wish.  To see the gINT Rules code module you must either merge the GLB into your library (Utilities:Lib Merge/Copy) or change to the included library (File:Change Library).
*************************************************

SPECIAL NOTES:
See the DESCRIPTION section above for detailed usage instructions.
*************************************************