home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 32 / IOPROG_32.ISO / SOFT / SqlEval7 / devtools / samples / sqldmo / vb / idxtest / idxtest.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-04-05  |  25.9 KB  |  762 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Begin VB.Form frmIdxTest 
  4.    Caption         =   "Index Test"
  5.    ClientHeight    =   5550
  6.    ClientLeft      =   645
  7.    ClientTop       =   945
  8.    ClientWidth     =   9405
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   5550
  13.    ScaleWidth      =   9405
  14.    Begin VB.Frame frameTestSProcs 
  15.       Caption         =   "Test selected stored procedures with new index on table"
  16.       Enabled         =   0   'False
  17.       Height          =   1395
  18.       Left            =   180
  19.       TabIndex        =   23
  20.       Top             =   4020
  21.       Width           =   9015
  22.       Begin MSFlexGridLib.MSFlexGrid gridResults 
  23.          Height          =   1035
  24.          Left            =   180
  25.          TabIndex        =   26
  26.          Top             =   240
  27.          Width           =   6735
  28.          _ExtentX        =   11880
  29.          _ExtentY        =   1826
  30.          _Version        =   65541
  31.          Rows            =   20
  32.          Cols            =   3
  33.          FixedCols       =   2
  34.       End
  35.       Begin VB.CommandButton cmdTest 
  36.          Caption         =   "&Test stored proc(s)"
  37.          Enabled         =   0   'False
  38.          Height          =   375
  39.          Left            =   7080
  40.          TabIndex        =   24
  41.          Top             =   240
  42.          Width           =   1695
  43.       End
  44.    End
  45.    Begin VB.Frame frameCreateIdx 
  46.       Caption         =   "Create new index"
  47.       Enabled         =   0   'False
  48.       Height          =   1695
  49.       Left            =   180
  50.       TabIndex        =   15
  51.       Top             =   2160
  52.       Width           =   9015
  53.       Begin VB.CommandButton cmdCreateIdx 
  54.          Caption         =   "C&reate index for test"
  55.          Enabled         =   0   'False
  56.          Height          =   375
  57.          Left            =   7080
  58.          TabIndex        =   22
  59.          Top             =   300
  60.          Width           =   1695
  61.       End
  62.       Begin VB.ListBox listColsNewIdx 
  63.          Enabled         =   0   'False
  64.          Height          =   1230
  65.          Left            =   4500
  66.          MultiSelect     =   1  'Simple
  67.          TabIndex        =   21
  68.          Top             =   300
  69.          Width           =   1995
  70.       End
  71.       Begin VB.CommandButton cmdRmvColFromIdx 
  72.          Caption         =   "<< Remove"
  73.          Enabled         =   0   'False
  74.          Height          =   375
  75.          Left            =   3120
  76.          TabIndex        =   19
  77.          Top             =   1200
  78.          Width           =   1215
  79.       End
  80.       Begin VB.CommandButton cmdAddColToIdx 
  81.          Caption         =   "Add >>"
  82.          Enabled         =   0   'False
  83.          Height          =   375
  84.          Left            =   3120
  85.          TabIndex        =   18
  86.          Top             =   780
  87.          Width           =   1215
  88.       End
  89.       Begin VB.ListBox listColsTable 
  90.          Enabled         =   0   'False
  91.          Height          =   1230
  92.          Left            =   960
  93.          MultiSelect     =   1  'Simple
  94.          Sorted          =   -1  'True
  95.          TabIndex        =   17
  96.          Top             =   300
  97.          Width           =   1995
  98.       End
  99.       Begin VB.Label lblIndexName 
  100.          Caption         =   "Index:"
  101.          Height          =   555
  102.          Left            =   6600
  103.          TabIndex        =   25
  104.          Top             =   960
  105.          Width           =   2175
  106.       End
  107.       Begin VB.Label lblColsInIdx 
  108.          Caption         =   "Colu&mns in index"
  109.          Enabled         =   0   'False
  110.          Height          =   495
  111.          Left            =   3660
  112.          TabIndex        =   20
  113.          Top             =   300
  114.          Width           =   675
  115.       End
  116.       Begin VB.Label lblColsInTbl 
  117.          Caption         =   "&Columns in table"
  118.          Enabled         =   0   'False
  119.          Height          =   495
  120.          Left            =   180
  121.          TabIndex        =   16
  122.          Top             =   300
  123.          Width           =   675
  124.       End
  125.    End
  126.    Begin VB.Frame frameDatabases 
  127.       Caption         =   "Database/Table/Stored Procedure"
  128.       Enabled         =   0   'False
  129.       Height          =   1455
  130.       Left            =   180
  131.       TabIndex        =   8
  132.       Top             =   540
  133.       Width           =   9015
  134.       Begin VB.ListBox listDatabases 
  135.          Enabled         =   0   'False
  136.          Height          =   1035
  137.          Left            =   960
  138.          Sorted          =   -1  'True
  139.          TabIndex        =   10
  140.          Top             =   300
  141.          Width           =   1995
  142.       End
  143.       Begin VB.ListBox listSProcs 
  144.          Enabled         =   0   'False
  145.          Height          =   1035
  146.          Left            =   6540
  147.          MultiSelect     =   1  'Simple
  148.          Sorted          =   -1  'True
  149.          TabIndex        =   14
  150.          Top             =   300
  151.          Width           =   2235
  152.       End
  153.       Begin VB.ListBox listTables 
  154.          Enabled         =   0   'False
  155.          Height          =   1035
  156.          Left            =   3540
  157.          Sorted          =   -1  'True
  158.          TabIndex        =   12
  159.          Top             =   300
  160.          Width           =   1995
  161.       End
  162.       Begin VB.Label lblSProc 
  163.          Caption         =   "St&ored procs and/or views to test"
  164.          Enabled         =   0   'False
  165.          Height          =   975
  166.          Left            =   5700
  167.          TabIndex        =   13
  168.          Top             =   300
  169.          Width           =   795
  170.       End
  171.       Begin VB.Label lblTable 
  172.          Caption         =   "Ta&ble"
  173.          Enabled         =   0   'False
  174.          Height          =   255
  175.          Left            =   3060
  176.          TabIndex        =   11
  177.          Top             =   300
  178.          Width           =   495
  179.       End
  180.       Begin VB.Label lblDatabase 
  181.          Caption         =   "&Database"
  182.          Enabled         =   0   'False
  183.          Height          =   255
  184.          Left            =   180
  185.          TabIndex        =   9
  186.          Top             =   300
  187.          Width           =   855
  188.       End
  189.    End
  190.    Begin VB.TextBox txtServer 
  191.       Height          =   285
  192.       Left            =   1020
  193.       TabIndex        =   1
  194.       Top             =   120
  195.       Width           =   1455
  196.    End
  197.    Begin VB.TextBox txtLogin 
  198.       Height          =   285
  199.       Left            =   3180
  200.       TabIndex        =   3
  201.       Top             =   120
  202.       Width           =   1455
  203.    End
  204.    Begin VB.TextBox txtPassword 
  205.       Height          =   285
  206.       IMEMode         =   3  'DISABLE
  207.       Left            =   5700
  208.       PasswordChar    =   "*"
  209.       TabIndex        =   5
  210.       Top             =   120
  211.       Width           =   1455
  212.    End
  213.    Begin VB.CommandButton cmdConnect 
  214.       Caption         =   "&Connect"
  215.       Default         =   -1  'True
  216.       Height          =   375
  217.       Left            =   7260
  218.       TabIndex        =   6
  219.       Top             =   120
  220.       Width           =   1215
  221.    End
  222.    Begin VB.CommandButton cmdExit 
  223.       Caption         =   "E&xit"
  224.       Height          =   375
  225.       Left            =   8580
  226.       TabIndex        =   7
  227.       Top             =   120
  228.       Width           =   615
  229.    End
  230.    Begin VB.Label lblServer 
  231.       Caption         =   "&Server"
  232.       Height          =   255
  233.       Left            =   180
  234.       TabIndex        =   0
  235.       Top             =   150
  236.       Width           =   735
  237.    End
  238.    Begin VB.Label lblLogin 
  239.       Caption         =   "&Login"
  240.       Height          =   255
  241.       Left            =   2580
  242.       TabIndex        =   2
  243.       Top             =   150
  244.       Width           =   615
  245.    End
  246.    Begin VB.Label lblPassword 
  247.       Caption         =   "&Password"
  248.       Height          =   255
  249.       Left            =   4740
  250.       TabIndex        =   4
  251.       Top             =   150
  252.       Width           =   855
  253.    End
  254. Attribute VB_Name = "frmIdxTest"
  255. Attribute VB_GlobalNameSpace = False
  256. Attribute VB_Creatable = False
  257. Attribute VB_PredeclaredId = True
  258. Attribute VB_Exposed = False
  259. Dim oSQLServer As SQLDMO.SQLServer
  260. Dim oCurrentDB As SQLDMO.Database
  261. Dim oCurrentTable As SQLDMO.Table
  262. Dim oTestIdx As SQLDMO.Index
  263. Dim bConnected As Boolean
  264. Private Sub cmdAddColToIdx_Click()
  265.     'If nothing selected, return.
  266.     If listColsTable.SelCount = 0 Then
  267.         Exit Sub
  268.     End If
  269.     'Add the selected columns to the list of columns for
  270.     'a new test index.
  271.     Dim nColToAdd As Integer
  272.     Dim idxAddAt As Integer
  273.     idxAddAt = listColsNewIdx.ListCount
  274.     For nColToAdd = listColsTable.ListCount - 1 To 0 Step -1
  275.         If listColsTable.Selected(nColToAdd) = True Then
  276.             listColsNewIdx.AddItem listColsTable.List(nColToAdd), idxAddAt
  277.             listColsTable.RemoveItem nColToAdd
  278.         End If
  279.     Next nColToAdd
  280.     cmdCreateIdx.Enabled = True
  281. End Sub
  282. Private Sub cmdConnect_Click()
  283.     On Error GoTo HandleError
  284.         
  285.     'If we're connected, then disconnect and clear lists.
  286.     If bConnected = True Then
  287.         oSQLServer.DisConnect
  288.         bConnected = False
  289.         cmdConnect.Caption = "&Connect"
  290.         EnableLoginPrompts (True)
  291.         
  292.         'Empty all lists and disable prompts.
  293.         FillEmptyDatabaseList (False)
  294.         EnableDatabasePrompts (False)
  295.         Exit Sub
  296.     End If
  297.     'Set mouse pointer to "Wait" cursor.
  298.     frmIdxTest.MousePointer = 11
  299.     'Attempt a connection, then fill the properties stuff.
  300.     oSQLServer.ApplicationName = "SQL-DMO Index Test"
  301.     'If no login name, use NT Integrated security in an attempt.
  302.     'to connect.
  303.     If Not (Len(txtLogin.Text)) Then
  304.         oSQLServer.LoginSecure = True
  305.     End If
  306.     oSQLServer.Connect txtServer.Text, txtLogin.Text, txtPassword.Text
  307.     bConnected = True
  308.     cmdConnect.Caption = "&Disconnect"
  309.     EnableLoginPrompts (False)
  310.     'Enable and fill database prompts from collections in SQLServer
  311.     'object.
  312.     EnableDatabasePrompts (True)
  313.     'Fill databases list. If any databases found, select first and
  314.     'fill tables collection.
  315.     FillEmptyDatabaseList (True)
  316.     If listDatabases.ListCount > 0 Then
  317.         listDatabases.ListIndex = 0
  318.         listDatabases_Click
  319.     End If
  320.     frmIdxTest.MousePointer = 1
  321.     Exit Sub
  322.         
  323. HandleError:
  324.     frmIdxTest.MousePointer = 1
  325.     PrintError
  326.     Exit Sub
  327. End Sub
  328. Private Sub cmdCreateIdx_Click()
  329.     CreateTestIndex (True)
  330. End Sub
  331. Private Sub cmdExit_Click()
  332.     Form_Unload (0)
  333.     End
  334. End Sub
  335. Private Sub cmdRmvColFromIdx_Click()
  336.     'If nothing in the list, test for index remove, then exit.
  337.     If listColsNewIdx.ListCount = 0 Then
  338.         Exit Sub
  339.     End If
  340.     Dim nColToRemove As Integer
  341.     For nColToRemove = listColsNewIdx.ListCount - 1 To 0 Step -1
  342.         If listColsNewIdx.Selected(nColToRemove) = True Then
  343.             listColsTable.AddItem listColsNewIdx.List(nColToRemove)
  344.             listColsNewIdx.RemoveItem (nColToRemove)
  345.         End If
  346.     Next nColToRemove
  347.     If listColsNewIdx.ListCount = 0 Then
  348.         CreateTestIndex (False)
  349.         cmdCreateIdx.Enabled = False
  350.     End If
  351. End Sub
  352. Private Sub CreateTestIndex(bCreate As Boolean)
  353.     On Error GoTo HandleError
  354.     If oTestIdx Is Nothing Then
  355.         'Nothing to do
  356.     Else
  357.         oTestIdx.Remove
  358.         Set oTestIdx = Nothing
  359.     End If
  360.     If bCreate = False Then
  361.         lblIndexName.Caption = "Index:"
  362.         Exit Sub
  363.     End If
  364.     frmIdxTest.MousePointer = 11
  365.     Dim ncol As Integer
  366.     Dim strColumns As String
  367.     Dim oNewIdx As New SQLDMO.Index
  368.     oNewIdx.Name = "idx_IdxTest"
  369.     oNewIdx.Type = SQLDMOIndex_Default
  370.     For ncol = 0 To listColsNewIdx.ListCount - 1
  371.         If Len(strColumns) Then
  372.             strColumns = strColumns + ","
  373.         End If
  374.         strColumns = strColumns + "[" + listColsNewIdx.List(ncol) + "]"
  375.     Next ncol
  376.     oNewIdx.IndexedColumns = strColumns
  377.     oCurrentTable.Indexes.Add oNewIdx
  378.     Set oTestIdx = oNewIdx
  379.     lblIndexName.Caption = "Index:" + Chr(10) + Chr(13) + oTestIdx.Name
  380.     EnableTestPrompts (True)
  381.     frmIdxTest.MousePointer = 1
  382.     Exit Sub
  383. HandleError:
  384.     frmIdxTest.MousePointer = 1
  385.     PrintError
  386.     Exit Sub
  387. End Sub
  388. Private Sub cmdTest_Click()
  389.     On Error GoTo ErrorHandler
  390.     Dim oQR As SQLDMO.QueryResults
  391.     Dim strExec As String
  392.     Dim strMessage As String
  393.     Dim nProc As Integer
  394.     Dim strSProc As String
  395.     Dim strSProcs As String
  396.     Dim strParams As String
  397.     Dim oDBObj As SQLDMO.DBObject
  398.     'Create and initialize statistics counters.
  399.     Dim CPUTime As Integer
  400.             
  401.     Dim TotalCPUTime As Integer
  402.     TotalCPUTime = 0
  403.     'Execute the chosen stored procedures and extract statistics.
  404.     For nProc = 0 To listSProcs.ListCount - 1
  405.         If listSProcs.Selected(nProc) = True Then
  406.             CPUTime = 0
  407.             
  408.             'Build the SQL stored procedure or view execution string.
  409.             strSProc = listSProcs.List(nProc)
  410.             Set oDBObj = oCurrentDB.GetObjectByName(strSProc)
  411.             If oDBObj.Type = SQLDMOObj_StoredProcedure Then
  412.                 If GetSProcParams(oCurrentDB.StoredProcedures(strSProc), strParams) = True Then
  413.                     strExec = "exec " + strSProc + " " + strParams
  414.                 Else
  415.                     strExec = ""
  416.                 End If
  417.             Else
  418.                 strExec = "select * from " + strSProc
  419.             End If
  420.             
  421.             If Len(strExec) Then
  422.                 ' Enable the SQL Server statistics timing option.
  423.                 Set oQR = oCurrentDB.ExecuteWithResults("set statistics time on")
  424.                 
  425.                 ' Execute SQL execution string, retrieve results and messages.
  426.                 Set oQR = oCurrentDB.ExecuteWithResultsAndMessages(strExec, , strMessage)
  427.                 
  428.                 ' Parse statistics results from the strMessage string.
  429.                 Do While InStr(1, strMessage, "CPU time = ") > 0
  430.                     strMessage = Right(strMessage, _
  431.                         Len(strMessage) - InStr(1, strMessage, "CPU time = ") - (Len("CPU time = ") - 1))
  432.                     Comma = InStr(1, strMessage, ",")
  433.                     CPUTime = CPUTime + Val(Left(strMessage, Comma - 1))
  434.                 Loop
  435.                 
  436.                 If Len(strSProcs) Then
  437.                     strSProcs = strSProcs + ","
  438.                 End If
  439.                 strSProcs = strSProcs + strSProc
  440.                 
  441.                 ' Disable SQL Server's statistics option
  442.                 Set oQR = oCurrentDB.ExecuteWithResults("set statistics time off")
  443.                 
  444.                 ' Keep running total of statistics for every stored procedure
  445.                 TotalCPUTime = TotalCPUTime + CPUTime
  446.             End If
  447.         End If
  448.     Next nProc
  449.     'Check to see if we did anything
  450.     If TotalCPUTime > 0 Then
  451.         Dim ncol As Integer
  452.         Dim strIdxCols As String
  453.         For ncol = 0 To listColsNewIdx.ListCount - 1
  454.             If Len(strIdxCols) Then
  455.                 strIdxCols = strIdxCols + "::"
  456.             End If
  457.             strIdxCols = strIdxCols + listColsNewIdx.List(ncol)
  458.         Next ncol
  459.         
  460.         'Display the results in the grid control
  461.         gridResults.Rows = gridResults.Rows + 1
  462.         gridResults.Row = gridResults.Rows - 1
  463.         gridResults.Col = 0
  464.         gridResults.Text = strIdxCols
  465.         gridResults.Col = 1
  466.         gridResults.Text = strSProcs
  467.         gridResults.Col = 2
  468.         gridResults.Text = TotalCPUTime
  469.     End If
  470.     frmIdxTest.MousePointer = 1
  471.     Exit Sub
  472. ErrorHandler:
  473.     frmIdxTest.MousePointer = 1
  474.     PrintError
  475.     Exit Sub
  476. End Sub
  477. Private Sub EmptyColsInIndex()
  478.     listColsNewIdx.Clear
  479. End Sub
  480. Private Sub EnableDatabasePrompts(bEnable As Boolean)
  481.     frameDatabases.Enabled = bEnable
  482.     lblDatabase.Enabled = bEnable
  483.     listDatabases.Enabled = bEnable
  484.     lblTable.Enabled = bEnable
  485.     listTables.Enabled = bEnable
  486.     lblSProc.Enabled = bEnable
  487.     listSProcs.Enabled = bEnable
  488. End Sub
  489. Private Sub EnableIndexPrompts(bEnable As Boolean)
  490.     frameCreateIdx.Enabled = bEnable
  491.     lblColsInTbl.Enabled = bEnable
  492.     listColsTable.Enabled = bEnable
  493.     cmdAddColToIdx.Enabled = bEnable
  494.     cmdRmvColFromIdx.Enabled = bEnable
  495.     lblColsInIdx.Enabled = bEnable
  496.     listColsNewIdx.Enabled = bEnable
  497. End Sub
  498. Private Sub EnableLoginPrompts(bEnable As Boolean)
  499.     lblServer.Enabled = bEnable
  500.     txtServer.Enabled = bEnable
  501.     lblLogin.Enabled = bEnable
  502.     txtLogin.Enabled = bEnable
  503.     lblPassword.Enabled = bEnable
  504.     txtPassword.Enabled = bEnable
  505. End Sub
  506. Private Sub EnableTestPrompts(bEnable As Boolean)
  507.     frameTestSProcs.Enabled = bEnable
  508.     gridResults.Enabled = bEnable
  509.     cmdTest.Enabled = bEnable
  510. End Sub
  511. Private Sub FillEmptyColsToIndex(bFill As Boolean)
  512.     listColsTable.Clear
  513.     If bFill = True Then
  514.         Dim oCol As SQLDMO.Column
  515.         For Each oCol In oCurrentTable.Columns
  516.             listColsTable.AddItem oCol.Name
  517.         Next oCol
  518.     End If
  519. End Sub
  520. Private Sub FillEmptyDatabaseList(bFill As Boolean)
  521.     listDatabases.Clear
  522.     If bFill = True Then
  523.         Dim oDB As SQLDMO.Database
  524.         For Each oDB In oSQLServer.Databases
  525.             If oDB.SystemObject = False Then
  526.                 listDatabases.AddItem oDB.Name
  527.             End If
  528.         Next oDB
  529.     End If
  530. End Sub
  531. Private Sub FillEmptyTableList(bFill As Boolean)
  532.     listTables.Clear
  533.     If bFill = True Then
  534.         Dim oTable As SQLDMO.Table
  535.         For Each oTable In oCurrentDB.Tables
  536.             If oTable.SystemObject = False Then
  537.                 listTables.AddItem oTable.Name
  538.             End If
  539.         Next oTable
  540.     End If
  541. End Sub
  542. Private Sub FillEmptySProcList(bFill As Boolean)
  543.     listSProcs.Clear
  544.     If bFill = True Then
  545.         Dim oQR As SQLDMO.QueryResults
  546.         Set oQR = oCurrentTable.EnumDependencies(SQLDMODep_Children)
  547.         
  548.         'If the object type is stored procedure or view, add it to
  549.         'the list of testable objects.
  550.         Dim nRow As Integer
  551.         Dim oType As SQLDMO.SQLDMO_OBJECT_TYPE
  552.         For nRow = 1 To oQR.Rows
  553.             oType = oQR.GetColumnLong(nRow, 1)
  554.             If oType = SQLDMOObj_StoredProcedure Or oType = SQLDMOObj_View Then
  555.                 listSProcs.AddItem oQR.GetColumnString(nRow, 2)
  556.             End If
  557.         Next nRow
  558.     End If
  559.     'Clean up dependent objects.
  560.     CreateTestIndex (False)
  561.     EmptyColsInIndex
  562.     FillEmptyColsToIndex (False)
  563.     EnableIndexPrompts (False)
  564.     cmdCreateIdx.Enabled = False
  565. End Sub
  566. Private Sub Form_Load()
  567.     bConnected = False
  568.     Set oSQLServer = New SQLDMO.SQLServer
  569.     oSQLServer.LoginTimeout = 15
  570.     oSQLServer.ODBCPrefix = False
  571.     'Initialize grid control's columns, widths, and headings.
  572.     gridResults.Rows = 1
  573.     gridResults.Cols = 3
  574.     gridResults.ColWidth(0) = 2500
  575.     gridResults.ColWidth(1) = 2400
  576.     gridResults.ColWidth(2) = 1300
  577.     gridResults.ColAlignment(2) = 1
  578.     gridResults.Col = 0
  579.     gridResults.Text = "Index Columns"
  580.     gridResults.Col = 1
  581.     gridResults.Text = "Stored Procs/Views"
  582.     gridResults.Col = 2
  583.     gridResults.Text = "CPU Time"
  584. End Sub
  585. Private Sub Form_Unload(Cancel As Integer)
  586.     On Error Resume Next
  587.     If bConnected = True Then
  588.         CreateTestIndex (False)
  589.         oSQLServer.DisConnect
  590.     End If
  591.     oSQLServer.Close
  592.     Set oSQLServer = Nothing
  593. End Sub
  594. Private Function GetSProcParams(oSP As SQLDMO.StoredProcedure, strParams As String) As Boolean
  595.     Dim oQR As SQLDMO.QueryResults
  596.     Set oQR = oSP.EnumParameters
  597.     'If there are no parameters, then we're fine, just continue
  598.     If oQR.Rows = 0 Then
  599.         GetSProcParams = True
  600.     Else
  601.         'Fill out the parameter dialog and display it. Return True if the
  602.         'user indicates continue.
  603.         Dim nParam As Integer
  604.         Dim strDType As String
  605.         Dim bIllegalParamFound As Boolean
  606.         bIllegalParamFound = False
  607.         
  608.         'Set for failure.
  609.         GetSProcParams = False
  610.         
  611.         frmIdxTestGetParams.bOK = False
  612.         
  613.         frmIdxTestGetParams.lblSProcName = oSP.Name
  614.         
  615.         frmIdxTestGetParams.gridParameters.Rows = oQR.Rows + 1
  616.         For nParam = 1 To oQR.Rows
  617.             If oQR.GetColumnBool(nParam, 5) = True Then
  618.                 bIllegalParamFound = True
  619.             Else
  620.                 frmIdxTestGetParams.gridParameters.Row = nParam
  621.                 
  622.                 frmIdxTestGetParams.gridParameters.Col = 0
  623.                 frmIdxTestGetParams.gridParameters.Text = _
  624.                     oQR.GetColumnString(nParam, 1)
  625.                 
  626.                 strDType = oQR.GetColumnString(nParam, 2)
  627.                 If InStr(1, strDType, "char") Or InStr(1, strDType, "binary") Then
  628.                     strDType = strDType + "(" + _
  629.                         oQR.GetColumnString(nParam, 3) + ")"
  630.                 End If
  631.                 frmIdxTestGetParams.gridParameters.Col = 1
  632.                 frmIdxTestGetParams.gridParameters.Text = strDType
  633.                 
  634.                 frmIdxTestGetParams.gridParameters.Col = 2
  635.                 frmIdxTestGetParams.gridParameters.Text = ""
  636.             End If
  637.         Next nParam
  638.         
  639.         If bIllegalParamFound = False Then
  640.             frmIdxTestGetParams.Show vbModal, Me
  641.             If frmIdxTestGetParams.bOK = True Then
  642.                 Dim strParam As String
  643.                 Dim strValue As String
  644.                 
  645.                 frmIdxTestGetParams.gridParameters.Col = 2
  646.                 For nParam = 1 To frmIdxTestGetParams.gridParameters.Rows - 1
  647.                     strParam = oQR.GetColumnString(nParam, 1)
  648.                     frmIdxTestGetParams.gridParameters.Row = nParam
  649.                     strValue = frmIdxTestGetParams.gridParameters.Text
  650.                     
  651.                     If Len(strValue) Then
  652.                         strDType = oQR.GetColumnString(nParam, 2)
  653.                         If InStr(1, strDType, "char") Or InStr(1, strDType, "text") Or InStr(1, strDType, "date") Then
  654.                             strValue = "'" + strValue + "'"
  655.                         End If
  656.                     Else
  657.                         strValue = "NULL"
  658.                     End If
  659.                     
  660.                     If Len(strParams) Then
  661.                         strParams = strParams + ","
  662.                     End If
  663.                     strParams = strParams + strParam + " = " + strValue
  664.                 Next nParam
  665.                 
  666.                 GetSProcParams = True
  667.             End If
  668.         End If
  669.     End If
  670. End Function
  671. Private Sub listDatabases_Click()
  672.     'If no item selected, simply return.
  673.     If listDatabases.ListIndex = -1 Or listDatabases.ListCount = 0 Then
  674.         Set oCurrentDB = Nothing
  675.         Set oCurrentTable = Nothing
  676.         FillEmptyTableList (False)
  677.         
  678.         Exit Sub
  679.     End If
  680.     'Set to "Wait" pointer.
  681.     frmIdxTest.MousePointer = 11
  682.     'Get the selected database.
  683.     Dim oDB As SQLDMO.Database
  684.     Set oDB = oSQLServer.Databases(listDatabases.List(listDatabases.ListIndex))
  685.     'If the database selected references the current one, return. Otherwise
  686.     'get the list of tables from the newly selected database.
  687.     If oCurrentDB Is Nothing Then
  688.         Set oCurrentDB = oDB
  689.     Else
  690.         If oCurrentDB.Name = oDB.Name Then
  691.             Exit Sub
  692.         End If
  693.         Set oCurrentDB = Nothing
  694.         Set oCurrentDB = oDB
  695.     End If
  696.     'Get the list of tables and select the first one.
  697.     FillEmptyTableList (True)
  698.     If listTables.ListCount > 0 Then
  699.         listTables.ListIndex = 0
  700.     End If
  701.     'Reset pointer.
  702.     frmIdxTest.MousePointer = 1
  703. End Sub
  704. Private Sub listSProcs_Click()
  705.     'If nothing selected, clear objects, reset prompts and return.
  706.     If listSProcs.SelCount = 0 Then
  707.         CreateTestIndex (False)
  708.         EmptyColsInIndex
  709.         FillEmptyColsToIndex (False)
  710.         EnableIndexPrompts (False)
  711.         cmdCreateIdx.Enabled = False
  712.         Exit Sub
  713.     End If
  714.     EnableIndexPrompts (True)
  715.     EnableTestPrompts (True)
  716.     'If any object is selected, then fill in columns list as required.
  717.     If listColsTable.ListCount = 0 Then
  718.         'Set to "Wait" pointer.
  719.         frmIdxTest.MousePointer = 11
  720.         
  721.         FillEmptyColsToIndex (True)
  722.         
  723.         'Reset pointer.
  724.         frmIdxTest.MousePointer = 1
  725.     End If
  726. End Sub
  727. Private Sub listTables_Click()
  728.     'If no database or no tables, clear stored proc/view list and return.
  729.     If oCurrentDB Is Nothing Or listTables.ListIndex = -1 Or listTables.ListCount = 0 Then
  730.         Set oCurrentTable = Nothing
  731.         FillEmptySProcList (False)
  732.     End If
  733.     'Set to "Wait" pointer.
  734.     frmIdxTest.MousePointer = 11
  735.     'Get the selected table.
  736.     Dim oTable As SQLDMO.Table
  737.     Set oTable = oCurrentDB.Tables(listTables.List(listTables.ListIndex))
  738.     'If the table selected references the current one, return. Otherwise
  739.     'get the list of dependent stored procedures and views.
  740.     If oCurrentTable Is Nothing Then
  741.         Set oCurrentTable = oTable
  742.     Else
  743.         If oCurrentTable.Name = oTable.Name Then
  744.             Exit Sub
  745.         End If
  746.         Set oCurrentTable = Nothing
  747.         Set oCurrentTable = oTable
  748.     End If
  749.     'Get the list of dependent stored procedures and views.
  750.     FillEmptySProcList (True)
  751.     listSProcs_Click
  752.     'Reset pointer.
  753.     frmIdxTest.MousePointer = 1
  754. End Sub
  755. Private Sub PrintError()
  756.     Dim errString As String
  757.     If Err.Number <> 0 Then
  758.         errString$ = Err.Source & " Error " & Err.Number & ": " & Err.Description
  759.         MsgBox errString$
  760.     End If
  761. End Sub
  762.