Copyright 2007 by gINT Software. All rights reserved worldwide.
GRA005.TXT

gINT Rules Code Add-In menus Samples - 005

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 and gINT Professional 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 Add-In generates a skeleton gINT Rules procedure for use on prepopulating and saving a table. There are actually two Add-In commands, both under the GRA005 menu, one for a procedure on empty data set and one for a procedure on save.

The Add-In assumes that you are using the variable "gsDataA" for the storage and manipulation of the grid data and further assumes that you are using the procedure "InitFieldsFnB" to check for the existence of the fields referenced in your code and to initialize the column positions in "gsDataA" for the fields.

The Add-In uses the standard conventions used by gINT Software. You are free to change the code to match your preferences.

The two procedures in GRA005 COMMON PROCEDURES are general purpose and can be used with other modules. They wrap text to a specified number of characters per line and generate a list of fields in any table in the current project. See the comments in those two procedures for further details.

Following is a sample result for prepopulation (gINT Rules Procedure on Empty Data Set):

Public Sub SampleInitialize
'*****************************************************
'05Feb2007 sc
'Description:
'  Initializes sample records for boreholes without sample
'  data. Inserts sample records to the depth of the hole.
'*****************************************************

  Const s_Field_Depth As String = "Depth"
  Const s_Field_Length As String = "Length"
  Const s_Field_Type As String = "Type"

  'Column positions of fields in the data array.
  Dim iPsDepth As Integer
  Dim iPsLength As Integer
  Dim iPsType As Integer

  Dim lRow As Long
  '------------------------

  'This procedure is only to be executed on starting data
  'entry for a New data Set. This procedure needs To be
  'assigned to the "gINTRules Procedure on Empty Dataset"
  'property of the table. If it is assigned to the save
  'procedure, it will wipe out existing data. The following
  'check ensures that that will not happen.
  If glNumRows > 0 Then
    Exit Sub
  End If

  'Obtain pointers to the field data within the data array.
  If InitFieldsFnB(s_Field_Depth, iPsDepth, _
                   s_Field_Length, iPsLength, _
                   s_Field_Type, iPsType) _
  Then
    'One or more of the required fields missing from the table.
    Exit Sub
  End If

  glNumRows = ...your assignment code here...
  ReDim gsDataA(0 To UBound(gsDataA, 1), 1 To glNumRows)

  With gINTRules.GridData
    For lRow = 1 To glNumRows
      gsDataA(iPsDepth, lRow) = ...your assignment code here...
      gsDataA(iPsLength, lRow) = ...your assignment code here...
      gsDataA(iPsType, lRow) = ...your assignment code here...
    Next lRow
  End With
End Sub

Following is a sample result for a gINT Rules Procedure on Save:

Public Sub SampleSave
'*****************************************************
'30May2006 sc
'Description:
'  Calculates the % recovery from the sample penetration
'  length and the recovery length.
'*****************************************************

  Const s_Field_Length As String = "Length"
  Const s_Field_Rec As String = "Rec"
  Const s_Field_RecLength As String = "Rec Length"

  'Column positions of fields in the data array.
  Dim iPsLength As Integer
  Dim iPsRec As Integer
  Dim iPsRecLength As Integer

  Dim iRec As Integer

  Dim lRow As Long

  Dim nLength As Single
  Dim nRecLength As Single

  Dim sLength As String
  Dim sRecLength As String
  '------------------------

  'Obtain pointers to the field data within the data array.
  If InitFieldsFnB(s_Field_Length, iPsLength, _
                   s_Field_RecLength, iPsRecLength, _
                   s_Field_Rec, iPsRec) _
  Then
    'One or more of the required fields missing from the table.
    Exit Sub
  End If

  With gINTRules.GridData
    For lRow = 1 To glNumRows
      sLength = gsDataA(iPsLength, lRow)
      sRecLength = gsDataA(iPsRecLength, lRow)

      ...your core code here...

      gsDataA(iPsRec, lRow) = ...your assignment code here...
    Next lRow
  End With
End Sub

There are a number of dialogs and message boxes that are used to guide you through the process:
1. An initial message box appears that shows you the current table name. All work is done with the current table. The message box gives you the opportunity to cancel the process if you are in the wrong table.

2. A dialog appears asking for the procedure name, author's name, and procedure description. Only the procedure name is required.

3. A picklist appears with all fields in the current table. Select the field or fields that you will be working with in your final procedure.

4. For the save procedure:
  A. A picklist appears with the fields selected in step 3. Select the field or fields from which you will be reading data. Note that required fields will not be shown. It is assumed that required fields will be read. Note that a field can be both read from and written to. It is possible, although not likely, that you will only be writing to certain fields and reading the values of none of them. If this is the case, just click the [Ok] button with none of the fields selected in this dialog.

  B. The same picklist appears as in step 4A. Select the field or fields into which your procedure will write results. Required fields will not be shown. It is assumed that required fields will be read but not written to. For procedures that will only be validating data, there will be no fields to which you write data. In this case, select none of the fields in the list and click the [Ok] button.

5. A message box appears informing you that the code skeleton has been written to the Windows clipboard. To insert, move to the Code window of the desired module and paste (Ctrl+V) into the appropriate location.

Revision History
================
24Jun2007:
Under certain conditions the '----------------- line that should appear under the variable declaration section for the procedure on save appears right of the last variable declaration. This has been fixed.

05Feb2007:
Initial public upload
*************************************************

INCLUDED FILES:
GRA005.GLB:
  Add-Ins:   GRA005 - gINT Rules Procedure on Empty Dataset
             GRA005 - gINT Rules Procedure on Save

  gINT Rules code modules:
    GRA005:  Main
             AssignResults
             CurrentTableIsIncorrectFnB
             DimensionVariableValues
             DimFieldColumnPositionsFnS
             FieldsGeneralProcessing
             GintRulesProcedureOnEmptyDataset
             GintRulesProcedureOnSave
             InitializeFieldPositions
             ProcedureInfoAbortedFnB
             SelectFieldsAbortedFnB
             WriteCode

    GRA005 COMMON PROCEDURES:  TableFieldList
                               WrapTextFnS
*************************************************

INSTALLATION PROCEDURE:
Copy the files wherever you prefer.  To see the gINT Rules Add-In and 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.
*************************************************