home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / sql / vbsql / cursors.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-04-03  |  25.6 KB  |  795 lines

  1. VERSION 2.00
  2. Begin Form PrimaryWindow 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Cursor Scroll Bar Example"
  6.    ForeColor       =   &H00000000&
  7.    Height          =   7215
  8.    Icon            =   CURSORS.FRX:0000
  9.    Left            =   990
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   6285
  14.    ScaleWidth      =   7725
  15.    Top             =   -30
  16.    Width           =   7845
  17.    Begin ListBox Cursor_Buffer 
  18.       FontBold        =   -1  'True
  19.       FontItalic      =   0   'False
  20.       FontName        =   "Courier"
  21.       FontSize        =   9.75
  22.       FontStrikethru  =   0   'False
  23.       FontUnderline   =   0   'False
  24.       Height          =   2955
  25.       Left            =   120
  26.       TabIndex        =   18
  27.       Top             =   3240
  28.       Width           =   7215
  29.    End
  30.    Begin VScrollBar VScroll1 
  31.       Height          =   3255
  32.       LargeChange     =   15
  33.       Left            =   7320
  34.       Max             =   500
  35.       SmallChange     =   15
  36.       TabIndex        =   20
  37.       Top             =   3000
  38.       Width           =   255
  39.    End
  40.    Begin VBSQL VBSQL1 
  41.       Caption         =   "SQL Error/Message"
  42.       Height          =   255
  43.       Left            =   5160
  44.       Top             =   2760
  45.       Visible         =   0   'False
  46.       Width           =   2175
  47.    End
  48.    Begin Frame Frame2 
  49.       BackColor       =   &H00C0C0C0&
  50.       Caption         =   "Cursor Information"
  51.       Height          =   1575
  52.       Left            =   120
  53.       TabIndex        =   5
  54.       Top             =   1080
  55.       Width           =   7455
  56.       Begin CommandButton Update_Button 
  57.          Caption         =   "&Update"
  58.          Height          =   375
  59.          Left            =   6360
  60.          TabIndex        =   16
  61.          Top             =   1080
  62.          Width           =   975
  63.       End
  64.       Begin ComboBox CC_List 
  65.          Height          =   300
  66.          Left            =   2160
  67.          Style           =   2  'Dropdown List
  68.          TabIndex        =   13
  69.          Top             =   1080
  70.          Width           =   3255
  71.       End
  72.       Begin CommandButton Close_Button 
  73.          Caption         =   "C&lose"
  74.          Height          =   375
  75.          Left            =   6360
  76.          TabIndex        =   15
  77.          Top             =   720
  78.          Width           =   975
  79.       End
  80.       Begin TextBox IntN_value 
  81.          Height          =   285
  82.          Left            =   4800
  83.          TabIndex        =   11
  84.          Text            =   "Text1"
  85.          Top             =   720
  86.          Width           =   495
  87.       End
  88.       Begin ComboBox Sensitivity_List 
  89.          Height          =   300
  90.          Left            =   2160
  91.          Style           =   2  'Dropdown List
  92.          TabIndex        =   9
  93.          Top             =   720
  94.          Width           =   2175
  95.       End
  96.       Begin CommandButton Open_Button 
  97.          Caption         =   "&Open "
  98.          Height          =   375
  99.          Left            =   6360
  100.          TabIndex        =   14
  101.          Top             =   360
  102.          Width           =   975
  103.       End
  104.       Begin TextBox Fetch_size 
  105.          Height          =   285
  106.          Left            =   2160
  107.          TabIndex        =   7
  108.          Text            =   "1"
  109.          Top             =   360
  110.          Width           =   375
  111.       End
  112.       Begin Label Label3 
  113.          BackColor       =   &H00C0C0C0&
  114.          Caption         =   "Concurrenc&y Control:"
  115.          Height          =   210
  116.          Left            =   120
  117.          TabIndex        =   12
  118.          Top             =   1080
  119.          Width           =   1845
  120.       End
  121.       Begin Label Label8 
  122.          BackColor       =   &H00C0C0C0&
  123.          Caption         =   "&N:"
  124.          Height          =   255
  125.          Left            =   4440
  126.          TabIndex        =   10
  127.          Top             =   720
  128.          Width           =   255
  129.       End
  130.       Begin Label Label2 
  131.          BackColor       =   &H00C0C0C0&
  132.          Caption         =   "Cursor &Sensitivity:"
  133.          Height          =   225
  134.          Left            =   120
  135.          TabIndex        =   8
  136.          Top             =   720
  137.          Width           =   1605
  138.       End
  139.       Begin Label Label6 
  140.          BackColor       =   &H00C0C0C0&
  141.          Caption         =   "(Max = 15)"
  142.          Height          =   255
  143.          Left            =   2640
  144.          TabIndex        =   19
  145.          Top             =   360
  146.          Width           =   975
  147.       End
  148.       Begin Label Label5 
  149.          BackColor       =   &H00C0C0C0&
  150.          Caption         =   "Rows per &Fetch:"
  151.          Height          =   240
  152.          Left            =   120
  153.          TabIndex        =   6
  154.          Top             =   360
  155.          Width           =   1815
  156.       End
  157.    End
  158.    Begin Frame Frame1 
  159.       BackColor       =   &H00C0C0C0&
  160.       Caption         =   "Object"
  161.       Height          =   855
  162.       Left            =   120
  163.       TabIndex        =   0
  164.       Top             =   120
  165.       Width           =   7455
  166.       Begin ComboBox Table_List 
  167.          Height          =   300
  168.          Left            =   4800
  169.          TabIndex        =   4
  170.          Text            =   "Table_List"
  171.          Top             =   360
  172.          Width           =   2295
  173.       End
  174.       Begin ComboBox Database_List 
  175.          Height          =   300
  176.          Left            =   1320
  177.          TabIndex        =   2
  178.          Text            =   "Database_List"
  179.          Top             =   360
  180.          Width           =   2295
  181.       End
  182.       Begin Label Label4 
  183.          BackColor       =   &H00C0C0C0&
  184.          Caption         =   "&Table:"
  185.          Height          =   225
  186.          Left            =   3840
  187.          TabIndex        =   3
  188.          Top             =   360
  189.          Width           =   735
  190.       End
  191.       Begin Label Label1 
  192.          BackColor       =   &H00C0C0C0&
  193.          Caption         =   "&Database:"
  194.          Height          =   210
  195.          Left            =   120
  196.          TabIndex        =   1
  197.          Top             =   360
  198.          Width           =   1005
  199.       End
  200.    End
  201.    Begin Label COLUMN_LABEL 
  202.       BorderStyle     =   1  'Fixed Single
  203.       Caption         =   "Label8"
  204.       FontBold        =   -1  'True
  205.       FontItalic      =   0   'False
  206.       FontName        =   "Courier"
  207.       FontSize        =   9.75
  208.       FontStrikethru  =   0   'False
  209.       FontUnderline   =   0   'False
  210.       Height          =   255
  211.       Left            =   120
  212.       TabIndex        =   21
  213.       Top             =   3000
  214.       Width           =   7215
  215.    End
  216.    Begin Label Label7 
  217.       BackColor       =   &H00C0C0C0&
  218.       Caption         =   "&Results:"
  219.       Height          =   255
  220.       Left            =   120
  221.       TabIndex        =   17
  222.       Top             =   2760
  223.       Width           =   855
  224.    End
  225.    Begin Menu Menu_File 
  226.       Caption         =   "&Connect"
  227.       Begin Menu Logon_Selection 
  228.          Caption         =   "&Logon"
  229.       End
  230.       Begin Menu Log_Off_Selection 
  231.          Caption         =   "Log &Off"
  232.       End
  233.       Begin Menu Exit_Selection 
  234.          Caption         =   "&Exit"
  235.       End
  236.    End
  237.    Begin Menu Menu_Help 
  238.       Caption         =   "&Help"
  239.       Begin Menu About_Selection 
  240.          Caption         =   "&About..."
  241.       End
  242.    End
  243. Sub About_Selection_Click ()
  244.     About_Form.Show 1
  245. End Sub
  246. Sub BeginTran ()
  247.     Results% = ExecuteSQLCommand("begin tran")
  248.     Do While SqlResults(SqlConn%) <> NOMORERESULTS
  249.     Do While SqlNextRow(SqlConn%) <> NOMOREROWS
  250.     Loop
  251.     Loop
  252.     OpenTran% = True
  253. End Sub
  254. Sub CC_List_Click ()
  255.     If Sensitivity_List.ListIndex = -1 Or Table_List.ListIndex = -1 Then
  256.     Open_Button.Enabled = False
  257.     Else
  258.     Open_Button.Enabled = True
  259.     End If
  260. End Sub
  261. Sub ClearCursorBuffer ()
  262. Do While Cursor_Buffer.ListCount
  263.     Cursor_Buffer.RemoveItem 0
  264. End Sub
  265. Sub ClearDatabaseList ()
  266. Rem Clear all databases out of list box
  267.     Do While Database_List.ListCount
  268.     Database_List.RemoveItem 0
  269.     Loop
  270.     Database_List.Text = ""
  271. End Sub
  272.  Sub ClearOutputBuffer ()
  273.  For i% = 0 To 19
  274.     OutputData(i%) = ""
  275.  Next i%
  276. End Sub
  277. Sub ClearTableList ()
  278.     Rem Clear all tables out of list box
  279.     Do While Table_List.ListCount
  280.     Table_List.RemoveItem 0
  281.     Loop
  282.     Table_List.Text = ""
  283. End Sub
  284. Sub Close_Button_Click ()
  285.     If OpenTran% Then
  286.     CommitTran
  287.     End If
  288.     SqlCursorClose CursorHandle%
  289.     Open_Button.Enabled = True
  290.     Close_Button.Enabled = False
  291.     Update_Button.Enabled = False
  292.     Fetch_Size.Enabled = True
  293.     Sensitivity_List.Enabled = True
  294.     CC_List.Enabled = True
  295.     IntN_value.Enabled = True
  296.     COLUMN_LABEL.Caption = ""
  297.     ClearCursorBuffer
  298. End Sub
  299. Sub CommitTran ()
  300.     Results% = ExecuteSQLCommand("commit tran")
  301.     Do While SqlResults(SqlConn%) <> NOMORERESULTS
  302.     Do While SqlNextRow(SqlConn%) <> NOMOREROWS
  303.     Loop
  304.     Loop
  305. OpenTran% = False
  306. End Sub
  307. Sub Database_List_Click ()
  308. Rem This routine will use the selected database, get all the user
  309. Rem tables in the database, and change the primary window title
  310. Rem to reflect the database change.
  311.     DatabaseSelection$ = Database_List.Text
  312.     Results% = SqlUse(SqlConn%, DatabaseSelection$)
  313.     If Results% = SUCCEED Then
  314.     PrimaryWindow.MousePointer = 11
  315.     RetrieveTableNames
  316.     PrimaryWindow.MousePointer = 0
  317.     DatabaseName = SqlName$(SqlConn%)
  318.     ChangePrimaryWindowCaption
  319.     If Table_List.ListIndex = -1 Or Sensitivity_List.ListIndex = -1 Or CC_List.ListIndex = -1 Then
  320.         Open_Button.Enabled = False
  321.     Else
  322.         Open_Button.Enabled = True
  323.     End If
  324.     End If
  325. End Sub
  326. Sub Exit_Selection_Click ()
  327.     ExitApplication
  328.     End
  329. End Sub
  330. Sub Fetch_First ()
  331.     ClearCursorBuffer
  332.     If Not OpenTran% Then
  333.     BeginTran
  334.     Else
  335.     CommitTran
  336.     BeginTran
  337.     End If
  338.     Results% = SqlCursorFetch%(CursorHandle%, FETCHFIRST, 0)
  339.     If Results% = SUCCEED And Int(RowStatus&(0)) <> FTCENDOFRESULTS% Then
  340.     ProcessCursorRows
  341.     Update_Button.Enabled = True
  342.     FillCursorBuffer -1        'display the data
  343.     Else
  344.     MsgBox "Problem fetching cursor.", 0, "Cursor Example"
  345.     End If
  346. End Sub
  347. Sub Fetch_Last ()
  348.     If Not OpenTran% Then
  349.     BeginTran
  350.     Else
  351.     CommitTran
  352.     BeginTran
  353.     End If
  354.     Results% = SqlCursorFetch%(CursorHandle%, FETCHLAST, 0)
  355.     If Results% = SUCCEED And Int(RowStatus&(0)) <> FTCENDOFRESULTS% Then
  356.     ProcessCursorRows
  357.     Update_Button.Enabled = True
  358.     FillCursorBuffer -1        'display the data
  359.     Else
  360.     MsgBox "Problem fetching cursor.", 0, "Cursor Example"
  361.     End If
  362. End Sub
  363. Sub Fetch_Next ()
  364. Rem This routine will get this next batch of rows
  365.     If Not OpenTran% Then
  366.     BeginTran
  367.     Else
  368.     CommitTran
  369.     BeginTran
  370.     End If
  371.     Results% = SqlCursorFetch%(CursorHandle%, FETCHNEXT, 0)
  372.     If Results% = SUCCEED And Int(RowStatus&(0)) <> FTCENDOFRESULTS% Then
  373.     ProcessCursorRows
  374.     Update_Button.Enabled = True
  375.     FillCursorBuffer -1        'display the data
  376.     Else
  377.     MsgBox "Problem fetching cursor. You are more than likely at the end of the result set", 0, "Cursor Example"
  378.     End If
  379. End Sub
  380. Sub Fetch_Previous ()
  381. Rem This routine will get the previous batch of rows
  382.     If Not OpenTran% Then
  383.     BeginTran
  384.     Else
  385.     CommitTran
  386.     BeginTran
  387.     End If
  388.     Results% = SqlCursorFetch%(CursorHandle%, FETCHPREV, 0)
  389.     If Results% = SUCCEED And Int(RowStatus&(0)) <> FTCENDOFRESULTS% Then
  390.     ProcessCursorRows
  391.     Update_Button.Enabled = True
  392.     FillCursorBuffer -1        'display the data
  393.     Else
  394.     MsgBox "Problem fetching cursor.", 0, "Cursor Example"
  395.     End If
  396. End Sub
  397. Sub Fetch_Random (Rownum As Integer)
  398. Rem This routine will get a row number to start fetching from
  399.     If Not OpenTran% Then
  400.     BeginTran
  401.     Else
  402.     CommitTran
  403.     BeginTran
  404.     End If
  405.     Results% = SqlCursorFetch%(CursorHandle%, FETCHRANDOM, Rownum%)
  406.     If Results% = SUCCEED And Int(RowStatus&(0)) <> FTCENDOFRESULTS% Then
  407.     ProcessCursorRows
  408.     Update_Button.Enabled = True
  409.     FillCursorBuffer -1        'display the data
  410.     Else
  411.     MsgBox "Problem fetching cursor.", 0, "Cursor Example"
  412.     End If
  413. End Sub
  414. Sub Fetch_Relative (ScrollValue As Integer)
  415. Rem This routine will get a batch relative to the selected row
  416. Rem First Calculate where to start the fetch
  417.     MaxRows% = Vscroll1.Max
  418.     n = (ScrollValue * MaxRows%) / 100
  419.     Rownum% = n - CursorSliderValue%
  420. Rem Fetch the rows
  421.     If Not OpenTran% Then
  422.     BeginTran
  423.     Else
  424.     CommitTran
  425.     BeginTran
  426.     End If
  427.     Results% = SqlCursorFetch%(CursorHandle%, FETCHRELATIVE, Rownum%)
  428.     If Results% = SUCCEED And Int(RowStatus&(0)) <> FTCENDOFRESULTS% Then
  429.     ProcessCursorRows
  430.     Update_Button.Enabled = True
  431.     FillCursorBuffer -1        'display the data
  432.     Else
  433.     MsgBox "Problem fetching cursor.", 0, "Cursor Example"
  434.     End If
  435. End Sub
  436. Sub Fetch_size_LostFocus ()
  437. Rem Make sure the fetch size fits in the results list box to avoid scrolling
  438.     Num% = Val(Fetch_Size.Text) * Val(IntN_value.Text)
  439.     If Val(Fetch_Size.Text) < 1 Or Val(Fetch_Size.Text) > 15 Then
  440.     MsgBox "Value must be between 1 and 15", 0, "Cursor Example"
  441.     Fetch_Size.SetFocus
  442.     End If
  443. End Sub
  444. Sub FillCursorBuffer (x As Integer)
  445. Rem If x% >= 0, then we are doing a horizontal scroll
  446. Rem Clear the list box
  447. Rem Fill the list box with the shifted data
  448.     If x% >= 0 Then
  449.     ClearCursorBuffer
  450.     startshift% = x%
  451.     rowlen& = Len(OutputData(0))
  452.     i% = 0
  453.     While OutputData(i%) <> ""
  454.     If i% <= 2 Then
  455.     If x% = 0 Then startshift% = 1
  456.     Cursor_Buffer.AddItem Mid$(OutputData(i%), startshift%, rowlen&)
  457.     Else
  458.     If x% = 0 Then startshift% = 2
  459.     Cursor_Buffer.AddItem Mid$(OutputData(i%), startshift% - 1, rowlen&)
  460.     End If
  461.     i% = i% + 1
  462.     Wend
  463. Rem First fill the buffer with the headings
  464. Rem Then fill in the data
  465.     Else
  466.     i% = 0
  467.     While OutputData(i%) <> ""
  468.         Cursor_Buffer.AddItem OutputData(i%)
  469.         i% = i% + 1
  470.     Wend
  471.     End If
  472. End Sub
  473. Sub Form_Load ()
  474. Rem Initialize the application
  475.     PrimaryWindowTitle = "Cursor Example"
  476.     ChangePrimaryWindowCaption
  477.     InitializeApplication
  478.     MsgBox DBLIB_VERSION$, 0, "Cursor Example"
  479. Rem Set the initial state of each of the controls in the form
  480.     Sensitivity_List.AddItem "Static"
  481.     Sensitivity_List.AddItem "Keyset driven"
  482.     Sensitivity_List.AddItem "Dynamic"
  483.     Sensitivity_List.AddItem "Int N"
  484.     CC_List.AddItem "Read only"
  485.     CC_List.AddItem "Locking control"
  486.     CC_List.AddItem "Optimistic concurrency"
  487.     CC_List.AddItem "Optimistic concurrency by values"
  488.     Logon_Selection.Enabled = True
  489.     Log_Off_Selection.Enabled = False
  490.     Exit_Selection.Enabled = True
  491.     Open_Button.Enabled = False
  492.     Close_Button.Enabled = False
  493.     Update_Button.Enabled = False
  494.     OpenTran% = False
  495.     COLUMN_LABEL.Caption = ""
  496.     ClearCursorBuffer
  497.     ClearDatabaseList
  498.     ClearTableList
  499.     IntN_value.Text = "0"
  500. End Sub
  501. Sub Log_Off_Selection_Click ()
  502. Rem Set the state of the controls
  503. Rem Logoff
  504.     ClearDatabaseList
  505.     ClearTableList
  506.     Open_Button.Enabled = False
  507.     Close_Button.Enabled = False
  508.     Update_Button.Enabled = False
  509.     Logoff
  510.     Logon_Selection.Enabled = True
  511.     Log_Off_Selection.Enabled = False
  512.     Exit_Selection.Enabled = True
  513. End Sub
  514. Sub Logon_Selection_Click ()
  515. Rem Logon to the server
  516. Rem Get the databases in the server and display them in the list box
  517. Rem Change the primary window caption to reflect current status
  518.     Login.Show 1
  519.     PrimaryWindow.MousePointer = 11
  520.     If CheckServerConnection() = 1 Then
  521.     Results% = GetDatabases(Database_List)
  522.     ChangePrimaryWindowCaption
  523.     Logon_Selection.Enabled = False
  524.     Log_Off_Selection.Enabled = True
  525.     End If
  526.     PrimaryWindow.MousePointer = 0
  527. End Sub
  528. Sub Open_Button_Click ()
  529. Rem Get the fetch size and keyset size
  530. Rem Redimension the rowstatus array
  531.     NumRowsInCursor% = Val(Fetch_Size.Text)
  532.     IntN% = Val(IntN_value.Text)
  533.     ReDim RowStatus&(NumRowsInCursor%)
  534. Rem Set the scroll option and concurrency control values
  535.     Select Case Sensitivity_List.Text
  536.     Case "Static"
  537.     ScrollOpt% = CURFORWARD%
  538.     Case "Keyset driven"
  539.         ScrollOpt% = CURKEYSET%
  540.     Case "Dynamic"
  541.     ScrollOpt% = CURDYNAMIC%
  542.     Case "Int N"
  543.     If IntN% <= 0 Then
  544.         MsgBox "You must Supply N", 0, "Cursor Example"
  545.         Exit Sub
  546.     Else
  547.         ScrollOpt% = IntN%
  548.     End If
  549.     End Select
  550.     Select Case CC_List.Text
  551.     Case "Read only"
  552.     Concuropt% = CURREADONLY%
  553.     Case "Locking control"
  554.     Concuropt% = CURLOCKCC%
  555.     Case "Optimistic concurrency"
  556.     Concuropt% = CUROPTCC%
  557.     Case "Optimistic concurrency by values"
  558.     Concuropt% = CUROPTCCVAL%
  559.     End Select
  560. Rem Setup the select statement and open the cursor
  561.     Statement$ = "select * from " + Table_List.Text
  562.     CursorHandle% = SqlCursorOpen(SqlConn%, Statement$, ScrollOpt%, Concuropt%, NumRowsInCursor%, RowStatus&(0))
  563.     If CursorHandle% <> FAIL Then
  564.     Open_Button.Enabled = False
  565.     Close_Button.Enabled = True
  566. Rem Get Column names and lengths
  567. Rem Output the column header
  568.     Results% = SqlCursorInfo%(CursorHandle%, NumCols%, NumRowsInKeyset&)
  569.     For ColCount% = 1 To NumCols%
  570.         Results% = SqlCursorColInfo%(CursorHandle%, ColCount%, colname$, Coltype%, ColLen&, UserType%)
  571.         CursorColName$(ColCount%) = colname$
  572.         CursorColLen&(ColCount%) = ColLen&
  573.     Next ColCount%
  574.     ClearOutputBuffer
  575.     ProcessCursorHeader
  576.     IntN_value.Enabled = False
  577.     Sensitivity_List.Enabled = False
  578.     CC_List.Enabled = False
  579. Rem Set the vertical scroll bar to <page up> and <page down> the size of the fetch
  580. Rem Determine the max value of VScroll1
  581. Rem     If we are dealing with a mixed scroll, then set to number (ScrollOpt% * IntN%) * an arbitrary number
  582. Rem         NOTE: You choose an arbitrary number because you want to be able to go outside of keyset.
  583. Rem     If Dealing with keyset or static scroll and we have enough room to store the whole keyset,
  584. Rem         then set max to full keyset size.
  585. Rem     Otherwise, we're dealing with Dynamic scroll or we can't fit the who keyset.
  586. Rem         Make a guess as to how big the keyset is by multiplying the "asked for"
  587. Rem         fetch size by some arbitrary number (we chose 10).
  588. Rem Fetch the first batch of rows
  589.     Vscroll1.SmallChange = NumRowsInCursor%
  590.     Vscroll1.LargeChange = Vscroll1.SmallChange
  591.     Vscroll1.Value = 0
  592.     Vscroll1.Refresh        'Refresh the vertical scrollbar
  593.     CursorSliderValue = 0
  594.     If IntN% <> 0 Then
  595.         Vscroll1.Max = (ScrollOpt% * IntN%) * 10
  596.     Else
  597.         If NumRowsInKeyset& > 0 Then
  598.         Vscroll1.Max = NumRowsInKeyset&
  599.         Else
  600.         Vscroll1.Max = NumRowsInCursor% * 10       'Note: the number 10 is an arbitrary number
  601.         End If
  602.     End If
  603.     Fetch_First
  604.     Else
  605.     MsgBox "Cursor failed to open.", 0, "Cursor Example"
  606.     End If
  607. End Sub
  608. Function PrepareString (String_In As String) As String
  609.     String_Out$ = ""
  610.     For i% = 1 To Len(String_In)
  611.     If Mid$(String_In, i%, 1) = Chr$(39) Then
  612.     String_Out$ = String_Out$ + Chr$(39) + Chr$(39)
  613.     Else
  614.     String_Out$ = String_Out$ + Mid$(String_In, i%, 1)
  615.     End If
  616.     Next
  617.     PrepareString = String_Out$
  618. End Function
  619. Sub ProcessCursorHeader ()
  620. Rem This routine gets and formats the cursor header
  621.     TABKEY$ = "    "
  622.     NEWLINE$ = Chr$(13) + Chr$(10)
  623.     colline$ = ""
  624.     For ColCount% = 1 To NumCols%
  625.     tmplen% = CursorColLen&(ColCount%)
  626.     If tmplen% > 256 Then tmplen% = 256
  627.     colname$ = CursorColName$(ColCount%)
  628.     actuallen& = Len(colname$)
  629.     If actuallen& < tmplen% Then
  630.     If ColCount% <> NumCols% Then
  631.         colline$ = colline$ + colname$ + Space$((tmplen% - actuallen&) + 1) + TABKEY$
  632.     Else
  633.         colline$ = colline$ + colname$ + Space$((tmplen% - actuallen&) + 1)
  634.     End If
  635.     Else
  636.     If ColCount% <> NumCols% Then
  637.         colline$ = colline$ + colname$ + TABKEY$
  638.     Else
  639.         colline$ = colline$ + colname$
  640.     End If
  641.     End If
  642.     Next ColCount%
  643. Rem Set the COLUMN_LABEL label
  644.     COLUMN_LABEL.Caption = colline$
  645. End Sub
  646. Sub ProcessCursorRows ()
  647. Rem This routine gets each of the cursor rows and displays them
  648.     TABKEY$ = Chr$(9)
  649.     colline$ = ""
  650.     ClearCursorBuffer
  651.     ClearOutputBuffer
  652. Rem    HScroll1.Refresh     'Refresh the horizontal scroll bar
  653. Rem Set the end of results and keyset values
  654.     ENDRESULTS% = FTCENDOFRESULTS% + 1
  655.     ENDKEYSET% = FTCENDOFRESULTS% + FTCENDOFKEYSET% + 1
  656. Rem Get the cursor data based on the row and column
  657.     For RowCount% = 1 To NumRowsInCursor%
  658.     For ColCount% = 1 To NumCols%
  659.         ColValue$ = SqlCursorData(CursorHandle%, RowCount%, ColCount%)
  660.         actuallen& = Len(ColValue$)
  661.         tmplen% = CursorColLen(ColCount%)
  662.         If tmplen% > 256 Then tmplen% = 256
  663.         If actuallen& < tmplen% Then
  664.         If ColCount% <> NumCols% Then
  665.             DataStr$ = DataStr$ + ColValue$ + Space$((tmplen% - actuallen&) + 1) + TABKEY$
  666.         Else
  667.             DataStr$ = DataStr$ + ColValue$ + Space$((tmplen% - actuallen&) + 1)
  668.         End If
  669.         Else
  670.         If ColCount% <> NumCols% Then
  671.             DataStr$ = DataStr$ + ColValue$ + TABKEY$
  672.         Else
  673.             DataStr$ = DataStr$ + ColValue$
  674.         End If
  675.         End If
  676.         ColValue$ = ""
  677.     Next ColCount%
  678.     OutputData(RowCount% - 1) = DataStr$
  679.     DataStr$ = ""
  680.     testval% = Int(RowStatus&(RowCount% - 1))
  681.     If testval% = ENDRESULTS% Or testval% = ENDKEYSET% Or testval% = FTCENDOFRESULTS% Then
  682.         Exit For
  683.     End If
  684.     Next RowCount%
  685. End Sub
  686. Sub RetrieveTableNames ()
  687. Rem Retrieve table names from SQL Server into list box
  688.     ClearTableList
  689.     Results% = ExecuteSQLCommand("Select name from sysobjects where type = 'U'")
  690.     Do While (SqlResults%(SqlConn%) <> NOMORERESULTS)
  691.     Do While (SqlNextRow(SqlConn%) <> NOMOREROWS)
  692.         Table_List.AddItem SqlData(SqlConn%, 1)
  693.     Loop
  694.     Loop
  695.     Table_List.Text = Table_List.List(0)
  696. End Sub
  697. Sub Sensitivity_List_Click ()
  698. Rem Make sure the required data is supplied before enabling the open button
  699.     If Table_List.ListIndex = -1 Or CC_List.ListIndex = -1 Then
  700.     Open_Button.Enabled = False
  701.     Else
  702.     Open_Button.Enabled = True
  703.     End If
  704. End Sub
  705. Sub Table_List_Click ()
  706. Rem Make sure the required data is supplied before enabling the open button
  707.     If Sensitivity_List.ListIndex = -1 Or CC_List.ListIndex = -1 Then
  708.     Open_Button.Enabled = False
  709.     Else
  710.     Open_Button.Enabled = True
  711.     End If
  712. End Sub
  713. Sub Update_Button_Click ()
  714. Rem Get the selected row number
  715.     Rownum% = Cursor_Buffer.ListIndex + 1
  716.     If Rownum% = 0 Then
  717.     Beep
  718.     MsgBox "Select a row to update.", 0, "Cursor Example"
  719.     Exit Sub
  720.     End If
  721. Rem Get column # to update and new value
  722.     ColNum$ = InputBox$("Number of column to update:", "Update")
  723.     If ColNum$ = "" Then Exit Sub
  724.     Value$ = InputBox$("Update column " + ColNum$ + " with value: ", "Update")
  725.     If Value$ = "" Then Exit Sub
  726.     Table$ = Table_List.Text
  727. Rem Determine name of column to update
  728. Rem Create the update string
  729.     Results% = SqlCursorColInfo(CursorHandle%, Val(ColNum$), colname$, Coltype%, ColLen&, UserType%)
  730.     UpdateValue$ = "set " + colname$ + "="
  731.     If Coltype% = SQLCHAR Or Coltype% = SQLVARCHAR Then
  732.        UpdateValue$ = UpdateValue$ + "'" + Value$ + "'"
  733.     Else
  734.     UpdateValue$ = UpdateValue$ + Value$
  735.     End If
  736. Rem Perform update
  737.     Results% = SqlCursor(CursorHandle%, CRSUPDATE, Rownum%, Table$, UpdateValue$)
  738. End Sub
  739. Sub VBSQL1_Error (SqlConn As Integer, Severity As Integer, ErrorNum As Integer, ErrorStr As String, RetCode As Integer)
  740. ' Call the required VBSQL error-handling function
  741. ' OSErr and OSErrStr not used in VBSQL for Windows, but DOS interprets
  742. ' anything other than -1 as an OS error
  743.     OsErr% = -1
  744.     RetCode% = UserSqlErrorHandler%(SqlConn, Severity%, ErrorNum%, OsErr%, ErrorStr$, OsErrStr$)
  745. End Sub
  746. Sub VBSQL1_Message (SqlConn As Integer, Message As Long, State As Integer, Severity As Integer, MsgStr As String)
  747.     UserSqlMsgHandler SqlConn, Message&, State%, Severity%, MsgStr$
  748. End Sub
  749. Sub VScroll1_Change ()
  750. If Vscroll1.Value = 0 And CursorSliderValue% = 0 Then Exit Sub
  751. Rem Define <Page Up> and <Page Down> values
  752. Rem Get the current scroll value
  753. PAGEUP = CursorSliderValue% - Vscroll1.SmallChange
  754. PAGEDOWN = CursorSliderValue% + Vscroll1.SmallChange
  755. x = Vscroll1.Value
  756. Rem Based on the scroll value, call the appropriate routine
  757. Rem If "Mixed" scroll and scrolling within the keyset, then just do a random
  758. If x > CursorSliderValue% And x < PAGEDOWN Then
  759.     If x > Vscroll1.SmallChange Then
  760.     Fetch_Random (x)
  761.     Else
  762.     Fetch_Relative (x)
  763.     End If
  764.     If x < CursorSliderValue% And x > PAGEUP Then
  765.     If x > Vscroll1.SmallChange Then
  766.         Fetch_Random (x)
  767.     Else
  768.         Fetch_Relative (x)
  769.     End If
  770.     Else
  771. Rem User is either doing a <Page Down>, <Page Up>, or Dynamic scrolling
  772.     Select Case x
  773.         Case Is = PAGEDOWN
  774.         Fetch_Next
  775.         Case Is = PAGEUP
  776.         Fetch_Previous
  777.         Case Is > PAGEDOWN
  778.         If ScrollOpt% = CURKEYSET% Then
  779.             Fetch_Random Int(x)
  780.         Else
  781.             Fetch_Relative Int(x)
  782.         End If
  783.         Case Is < PAGEUP
  784.         If ScrollOpt% = CURKEYSET% Then
  785.             Fetch_Random Int(x)
  786.         Else
  787.             Fetch_Relative Int(x)
  788.         End If
  789.     End Select
  790.     End If
  791. End If
  792. Rem Save the current scroll value for next time.
  793. CursorSliderValue = x
  794. End Sub
  795.