home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 6 Unleashed…sional Reference Edition) / Visual_Basic_6_Unleashed_Professional_Reference_Edition_Sams_1999.iso / Source / CHAP35 / 309X3702.TXT < prev    next >
Encoding:
Text File  |  1998-05-03  |  2.5 KB  |  85 lines

  1.  
  2. Private Sub cmdTest_Click()
  3.  
  4.     Dim Start, Finish, TotalTime          'Timer Variables
  5.     Dim rstPublishers As DAO.Recordset    'Holds the recordset used by Option 2
  6.     Dim strSQL As String                  'Update string for Option 2
  7.  
  8.     'With this timing example we just want to measure
  9.     'the update time. All connections and recordsets
  10.     'will be established prior to the timers starting.
  11.  
  12.     'Open the recordset for Option 1
  13.     If Option1.Value = True Then
  14.         'Open the Recordset object for the update
  15.         'Only retrieve records from the state of CA
  16.         '
  17.         Set rstPublishers = _
  18.             gdbBiblio.OpenRecordset("SELECT * FROM Publishers", _
  19.             dbOpenDynaset)
  20.     Else
  21.         strSQL = "UPDATE Publishers Set Comments = "
  22.         strSQL = strSQL & "'Buy VB Development Unleashed'"
  23.  
  24.     End If
  25.  
  26.     'Begin the timing operation
  27.     If Option1.Value = True Then
  28.         Start = Timer
  29.  
  30.         'DAO Update Timing Test - Note this is POOR
  31.         'Performance - DO NOT UPDATE Several DATABASE
  32.         'Records this way!
  33.         With rstPublishers
  34.             While Not .BOF And Not .EOF
  35.                 'Update the recordset comment field
  36.                 .Edit rstPublishers("Comments") = "Buy VB Development Unleashed"
  37.                 .Update
  38.  
  39.                 'Move to the next record
  40.                 .MoveNext
  41.             Wend
  42.         End With
  43.  
  44.         'End of Code time test
  45.         Finish = Timer
  46.  
  47.         'Clean up
  48.         rstPublishers.Close
  49.         Set rstPublishers = Nothing
  50.     Else
  51.         'Option 2 selected - SQL Updates and Transactions
  52.         Start = Timer
  53.  
  54.         'Note: The following code performs much faster!
  55.         'When updating, adding or deleting records using DAO
  56.         'use transactions to speed up the operation.
  57.         'When modifying or deleting a large number of records
  58.         'use SQL statements
  59.         gwksTest.BeginTrans
  60.         gdbBiblio.Execute strSQL
  61.         gwksTest.CommitTrans
  62.         'End of Code time test
  63.         Finish = Timer
  64.  
  65.     End If
  66.  
  67.     TotalTime = Finish - Start  ' Calculate total time.
  68.  
  69.     '
  70.     'Set up display results
  71.     '
  72.     If Option1.Value = True Then
  73.         'Option 1
  74.         lblOpt1.Caption = "Total time to execute " & _
  75.                             Option1.Caption & ": " & _
  76.                             TotalTime
  77.     Else
  78.         'Option 2
  79.         lblOpt2.Caption = "Total time to execute " & _
  80.                             Option2.Caption & ": " & _
  81.                             TotalTime
  82.     End If
  83.  
  84. End Sub
  85.