I have to write a lot of methods, that are going to be used by people after I have moved.
What I want is a consistent style particularly for commenting and layout.
Would anybody care to read thro' this example and comment on my current 'style'.
Any comments would be greatly appreciated.
The person taking over from me may not have much experience so do you think this example would be easy to understand and use.
Any comments on the actual working of the Sub would also be appreciated.
VB Code:
  1. '---------------------------------------------------------------------------------------
  2. ' Procedure      : FillFlexGrid
  3. ' DateTime       : 26/03/02 08:40
  4. ' Author         : Glen [email][email protected][/email]
  5. ' Purpose        : Fills MSFlexGrid with values in ADODB.Recordset
  6. '                  If NewGrid is set to false inRes values are added
  7. '                  to existing rows
  8. '                  Else old rows are deleted
  9. ' Pre-Conditions : inGrid must have 1 or 0 FixedColumns
  10. '                  inGrid must have 1 or 0 FixedRows
  11. '---------------------------------------------------------------------------------------
  12. '
  13. Public Sub FillFlexGrid(ByRef inGrid As MSFlexGrid, _
  14.                         ByVal inRes As ADODB.Recordset, _
  15.                Optional ByVal NewGrid As Boolean = True)
  16.    
  17.     'If a new grid remove old rows
  18.     'If NewGrid
  19.     If (NewGrid) Then
  20.         'If inGrid has a fixed row
  21.         If (inGrid.FixedRows = 1) Then
  22.             'Leave FixedRow
  23.             inGrid.Rows = 1
  24.         Else
  25.             'Clear all rows
  26.             inGrid.Rows = 0
  27.         End If ' (inGrid.FixedRows = 1) Then
  28.     End If ' (NewGrid)
  29.    
  30.     'Make inGrid columns = number of fields in inRes
  31.     inGrid.Cols = inRes.Fields.Count
  32.    
  33.     Dim thisRow As String   'To create row to add to grid
  34.     Dim i As Integer        'For loop count
  35.    
  36.     'If there are records
  37.     If (Not (inRes.BOF And inRes.EOF)) Then
  38.         'Go to the first one
  39.         inRes.MoveFirst
  40.         'While not at the last one
  41.         While (Not inRes.EOF)
  42.             'If inGrid has a fixed column
  43.             If (inGrid.FixedCols = 1) Then
  44.                 'Make 1st value TAB
  45.                 thisRow = vbTab
  46.             End If ' (inGrid.FixedCols = 1) Then
  47.             'While fields left
  48.             For i = 0 To inRes.Fields.Count - 1
  49.                 'Add field value to thisRow & TAB to move to next Column
  50.                 thisRow = thisRow & inRes.Fields(i).Value & vbTab
  51.             'Next field
  52.             Next ' For i = 0 To inRes.Fields.Count - 1
  53.             'Add thisRow to inGrid
  54.             inGrid.AddItem thisRow
  55.             'Reset
  56.             i = 0
  57.             'Reset
  58.             thisRow = ""
  59.             'Next record
  60.             inRes.MoveNext
  61.         Wend ' (Not inRes.EOF)
  62.     End If ' (Not (inRes.BOF And inRes.EOF)) Then
  63.    
  64. End Sub ' FillFlexGrid