home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Mainform
- BackColor = &H00FFFFC0&
- Caption = "Test SQL-Sombrero VBX - Author Application"
- ClientHeight = 4725
- ClientLeft = 1065
- ClientTop = 1470
- ClientWidth = 7680
- Height = 5130
- Left = 1005
- LinkTopic = "Form1"
- ScaleHeight = 4725
- ScaleWidth = 7680
- Top = 1125
- Width = 7800
- Begin DEMVBXCT SQLCTLIB1
- Left = 240
- Top = 3900
- End
- Begin ComboBox author_list
- FontBold = -1 'True
- FontItalic = 0 'False
- FontName = "Fixedsys"
- FontSize = 9
- FontStrikethru = 0 'False
- FontUnderline = 0 'False
- Height = 330
- Left = 240
- Style = 2 'Dropdown List
- TabIndex = 25
- Top = 120
- Width = 7095
- End
- Begin CommandButton delbut
- Caption = "Delete Author"
- Height = 615
- Left = 6000
- TabIndex = 24
- Top = 2040
- Visible = 0 'False
- Width = 1335
- End
- Begin CommandButton cancelbut
- Caption = "Cancel"
- Height = 495
- Left = 6240
- TabIndex = 23
- Top = 3840
- Visible = 0 'False
- Width = 855
- End
- Begin CommandButton newrec
- Caption = "Add New"
- Height = 615
- Left = 6000
- TabIndex = 22
- Top = 1320
- Visible = 0 'False
- Width = 1335
- End
- Begin CommandButton updbut
- Caption = "Update Info"
- Height = 615
- Left = 6000
- TabIndex = 21
- Top = 3120
- Visible = 0 'False
- Width = 1335
- End
- Begin CommandButton chgbut
- Caption = "Change Info"
- Height = 615
- Left = 6000
- TabIndex = 20
- Top = 600
- Visible = 0 'False
- Width = 1335
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 8
- Left = 1560
- MaxLength = 10
- TabIndex = 19
- Top = 3480
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 7
- Left = 1560
- MaxLength = 12
- TabIndex = 18
- Top = 3120
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 6
- Left = 1560
- MaxLength = 2
- TabIndex = 17
- Top = 2760
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 5
- Left = 1560
- MaxLength = 20
- TabIndex = 16
- Top = 2400
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 4
- Left = 1560
- MaxLength = 40
- TabIndex = 15
- Top = 2040
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 3
- Left = 1560
- MaxLength = 12
- TabIndex = 14
- Top = 1680
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 2
- Left = 1560
- MaxLength = 20
- TabIndex = 13
- Top = 1320
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 1
- Left = 1560
- MaxLength = 40
- TabIndex = 12
- Top = 960
- Visible = 0 'False
- Width = 3855
- End
- Begin TextBox Text1
- Enabled = 0 'False
- Height = 285
- Index = 0
- Left = 1560
- MaxLength = 11
- TabIndex = 11
- Top = 600
- Visible = 0 'False
- Width = 3855
- End
- Begin CommandButton exitbut
- Caption = "Exit"
- Height = 375
- Left = 4200
- TabIndex = 1
- Top = 3960
- Width = 1095
- End
- Begin CommandButton multibut
- Caption = "Logon"
- Height = 375
- Left = 1320
- TabIndex = 0
- Top = 3960
- Width = 1095
- End
- Begin Shape Shape2
- BorderWidth = 3
- Height = 2295
- Left = 5880
- Top = 480
- Visible = 0 'False
- Width = 1575
- End
- Begin Shape Shape1
- BorderWidth = 3
- Height = 1455
- Left = 5880
- Top = 3000
- Visible = 0 'False
- Width = 1575
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "Postal Code :"
- Height = 255
- Index = 8
- Left = 120
- TabIndex = 10
- Top = 3480
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "Country :"
- Height = 255
- Index = 7
- Left = 120
- TabIndex = 9
- Top = 3120
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "State :"
- Height = 255
- Index = 6
- Left = 120
- TabIndex = 8
- Top = 2760
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "City :"
- Height = 255
- Index = 5
- Left = 120
- TabIndex = 7
- Top = 2400
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "Address :"
- Height = 255
- Index = 4
- Left = 120
- TabIndex = 6
- Top = 2040
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "Phone # :"
- Height = 255
- Index = 3
- Left = 120
- TabIndex = 5
- Top = 1680
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "First Name :"
- Height = 255
- Index = 2
- Left = 120
- TabIndex = 4
- Top = 1320
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "Last Name :"
- Height = 255
- Index = 1
- Left = 120
- TabIndex = 3
- Top = 960
- Visible = 0 'False
- Width = 1215
- End
- Begin Label Label1
- Alignment = 1 'Right Justify
- BackColor = &H00FFFFC0&
- Caption = "Author Id :"
- Height = 255
- Index = 0
- Left = 120
- TabIndex = 2
- Top = 600
- Visible = 0 'False
- Width = 1215
- End
- Dim t(1 To 3) As String
- Sub author_list_Click ()
- show_author
- chgbut.Visible = True
- delbut.Visible = True
- End Sub
- Sub cancelbut_Click ()
- author_list.Enabled = True
- If author_list.ListIndex <> -1 Then
- chgbut.Visible = True
- delbut.Visible = True
- End If
- updbut.Visible = False
- newrec.Visible = True
- cancelbut.Visible = False
- For i = 0 To 8
- text1(i).Enabled = False
- Next
- show_author
- End Sub
- Sub chgbut_Click ()
- For i = 1 To 8
- text1(i).Enabled = True
- Next
- author_list.Enabled = False
- chgbut.Visible = False
- updbut.Visible = True
- newrec.Visible = False
- delbut.Visible = False
- cancelbut.Visible = True
- updflag = 1
- text1(1).SetFocus
- End Sub
- Sub delbut_Click ()
- updflag = 3
- updbut.Visible = True
- chgbut.Visible = False
- newrec.Visible = False
- cancelbut.Visible = True
- delbut.Visible = False
- author_list.Enabled = False
- End Sub
- Sub exitbut_Click ()
- If ctx_pointer <> 0 Then
- ret = VBCT_close(con_pointer, CS_FORCE_CLOSE)
- ret = VBCT_con_drop(con_pointer)
- ret = VBCT_exit(ctx_pointer, CS_FORCE_EXIT)
- ret = VBCS_ctx_drop(ctx_pointer)
- End If
- End
- End Sub
- Sub Form_Load ()
- updflag = 0
- ctx_pointer = 0
- cd$ = CompileDate()
- MsgBox "Compile Date - " & cd$
- End Sub
- Sub multibut_Click ()
- Dim ncols As Long
- Dim restype As Long
- Dim rows_read As Long
- logon.Show 1
- If multibut.Visible = True Then
- Exit Sub
- End If
- newrec.Visible = True
- ret = VBCT_command_str(cmd_pointer, CS_LANG_CMD, "select 'Author Id' = au_id , 'Last Name' = au_lname , 'First Name' = au_fname from authors", CS_UNUSED)
- ret = VBCT_send(cmd_pointer)
-
- result_ret = VBCT_results(cmd_pointer, restype)
- res$ = ""
- While result_ret = CS_SUCCEED
- Select Case restype
-
- Case CS_ROW_RESULT
- ' There are fetchable results available from 0 or more rows of tabular information
- ret = VBCT_res_info(cmd_pointer, CS_NUMDATA, ncols)
- ret = VBCT_do_binds(cmd_pointer)
- While ret = CS_SUCCEED Or ret = CS_ROW_FAIL
- ret = VBCT_fetch(cmd_pointer, 0, 0, 0, rows_read)
- If ret = CS_SUCCEED Then
- For i = 1 To ncols
- t(i) = VBCT_data(cmd_pointer, i)
- Next
- End If
- aitem$ = t(1) & Space(15 - Len(t(1))) & Left(t(2) & Space(41 - Len(t(2))), 20) & t(3)
- author_list.AddItem aitem$
- Wend
- Case CS_CMD_DONE, CS_CMD_SUCCEED, CS_CMD_FAIL
- Select Case restype
- Case CS_CMD_DONE
- rt$ = "CS_CMD_DONE"
- Case CS_CMD_SUCCEED
- rt$ = "CS_CMD_SUCCEED"
- Case CS_CMD_FAIL
- rt$ = "CS_CMD_FAIL"
- End Select
- ' MsgBox "Command status " & rt$ & " recieved"
- Case Else
- MsgBox "this command should never go here"
- End Select
- result_ret = VBCT_results(cmd_pointer, restype)
- Wend
-
- For i = 0 To 8
- label1(i).Visible = True
- text1(i).Visible = True
- Next
- author_list.Visible = True
- newrec.Visible = True
- shape1.Visible = True
- shape2.Visible = True
- End Sub
- Sub newrec_Click ()
- updflag = 2
- updbut.Visible = True
- chgbut.Visible = False
- newrec.Visible = False
- cancelbut.Visible = True
- delbut.Visible = False
- author_list.Enabled = False
- For i = 0 To 8
- text1(i).Enabled = True
- text1(i).Text = ""
- Next
- text1(0).SetFocus
- End Sub
- Sub show_author ()
- Dim restype As Long
- Dim ncols As Long
- Dim rows_read As Long
- lc = author_list.ListIndex
- If lc = -1 Then
- Exit Sub
- End If
- d$ = RTrim(Left(author_list.List(lc), 15))
- ret = VBCT_command_str(cmd_pointer, CS_LANG_CMD, "select * from authors where au_id = '" & d$ & "'", CS_UNUSED)
- ret = VBCT_send(cmd_pointer)
-
- result_ret = VBCT_results(cmd_pointer, restype)
- res$ = ""
- While result_ret = CS_SUCCEED
- Select Case restype
-
- Case CS_ROW_RESULT
- ' There are fetchable results available from 0 or more rows of tabular information
- ret = VBCT_res_info(cmd_pointer, CS_NUMDATA, ncols)
- ret = VBCT_do_binds(cmd_pointer)
- While ret = CS_SUCCEED Or ret = CS_ROW_FAIL
- ret = VBCT_fetch(cmd_pointer, 0, 0, 0, rows_read)
- If ret = CS_SUCCEED Then
- For i = 1 To ncols
- dat$ = VBCT_data(cmd_pointer, i)
- text1(i - 1).Text = dat$
- Next
- End If
- Wend
- Case CS_CMD_DONE, CS_CMD_SUCCEED, CS_CMD_FAIL
- Select Case restype
- Case CS_CMD_DONE
- rt$ = "CS_CMD_DONE"
- Case CS_CMD_SUCCEED
- rt$ = "CS_CMD_SUCCEED"
- Case CS_CMD_FAIL
- rt$ = "CS_CMD_FAIL"
- End Select
- ' MsgBox "Command status " & rt$ & " recieved"
- Case Else
- MsgBox "this command should never go here"
- End Select
- result_ret = VBCT_results(cmd_pointer, restype)
- Wend
- End Sub
- Sub SQLCTLIB1_CLIENTMESSAGE (Context As Long, connection As Long)
- Dim cmsg As CS_CLIENTMSG
- Dim ret As Long
- Dim layer As Long
- Dim origin As Long
- Dim severity As Long
- Dim number As Long
- crlf$ = Chr(13) & Chr(10)
- ret = VBCS_get_client_msg(cmsg)
- VBCS_decode_message cmsg.msgnumber, layer, origin, severity, number
- MsgBox "Client message # " & Str(number) & crlf$ & Left(cmsg.msgstring, cmsg.msgstringlen)
- End Sub
- Sub SQLCTLIB1_SERVERMESSAGE (Context As Long, connection As Long)
- Dim cmsg As CS_SERVERMSG
- Dim ret As Long
- Dim layer As Long
- Dim origin As Long
- Dim severity As Long
- Dim number As Long
- Dim outlen As Long
- crlf$ = Chr(13) & Chr(10)
- ret = VBCS_get_server_msg(cmsg)
- Dim appl As String
- appl = Space(50)
- ret = VBCT_con_props_str(connection, CS_GET, CS_APPNAME, appl, outlen)
- ' MsgBox "Message Status is " & Str(cmsg.status)
- If cmsg.status And CS_HASEED Then
- Dim cc As Long
- ret = VBCT_con_props_num(connection, CS_GET, CS_EED_CMD, cc, outlen)
- extendederrordata (cc)
- End If
- VBCS_decode_message cmsg.msgnumber, layer, origin, severity, number
- MsgBox "Server message # " & Str(number) & crlf$ & Left(cmsg.Text, cmsg.textlen)
- End Sub
- Sub Text1_KeyPress (index As Integer, keyascii As Integer)
- If updflag = 0 Then
- keyascii = 0
- End If
- End Sub
- Sub updbut_Click ()
- Dim sql As String
- If updflag = 3 Then
- GoTo dontcheck
- End If
- If text1(0).Text = "" Then
- MsgBox "Author Id cannot be NULL"
- Exit Sub
- End If
- If text1(1).Text = "" Then
- MsgBox "Last name cannot be NULL"
- Exit Sub
- End If
- If text1(2).Text = "" Then
- MsgBox "First name cannot be NULL"
- Exit Sub
- End If
- If text1(3).Text = "" Then
- MsgBox "Phone # cannot be NULL"
- Exit Sub
- End If
- dontcheck:
- If updflag = 1 Then
- ' In this application if the updflag is set to 1 then we are modifing the
- ' data for a particular row in the table authors. The following code will
- ' create a SQL Statement to 'UPDATE' the authors table where the au_id field
- ' is equal to the requested author id.
- sql = "update authors set "
- sql = sql & " au_lname = " & Chr(34) & text1(1).Text & Chr(34) & " ,"
- sql = sql & " au_fname = " & Chr(34) & text1(2).Text & Chr(34) & " ,"
- sql = sql & " phone = " & Chr(34) & text1(3).Text & Chr(34) & " ,"
- sql = sql & " address = " & Chr(34) & text1(4).Text & Chr(34) & " ,"
- sql = sql & " city = " & Chr(34) & text1(5).Text & Chr(34) & " ,"
- sql = sql & " state = " & Chr(34) & text1(6).Text & Chr(34) & " ,"
- sql = sql & " country = " & Chr(34) & text1(7).Text & Chr(34) & " ,"
- sql = sql & " postalcode = " & Chr(34) & text1(8).Text & Chr(34)
- sql = sql & " where au_id = " & Chr(34) & text1(0).Text & Chr(34)
- Else
- If updflag = 2 Then
- ' In this application if the updflag is set to 2 then we are adding
- ' data for a particular row in the table authors. The following code will
- ' create a SQL Statement to 'INSERT' a row into the authors table where the
- ' au_id field is equal to the requested author id.
- sql = "insert authors values ("
- For i = 0 To 7
- sql = sql & Chr(34) & text1(i).Text & Chr(34) & " , "
- Next
- sql = sql & Chr(34) & text1(8).Text & Chr(34) & ")"
- Else
- ' In this application if the updflag is set to 3 then we are deleting
- ' an author record from the table
- ' The SQL statement will delete a row from the table based on the
- ' primary key (au_id)
- sql = "delete from authors where au_id = " & Chr(34) & text1(0).Text & Chr(34)
- End If
- End If
- ret = process_no_rows(sql)
- If ret = 99 Then
- If updflag = 2 Then
- aitem$ = text1(0).Text & Space(15 - Len(text1(0).Text)) & Left(text1(1).Text & Space(41 - Len(text1(1).Text)), 20) & text1(2).Text
- author_list.AddItem aitem$
- MsgBox "Information added for au_id " & text1(0).Text
- author_list.ListIndex = author_list.ListCount - 1
- Else
- If updflag = 1 Then
- aitem$ = text1(0).Text & Space(15 - Len(text1(0).Text)) & Left(text1(1).Text & Space(41 - Len(text1(1).Text)), 20) & text1(2).Text
- MsgBox "Information changed for au_id " & text1(0).Text
- lc = author_list.ListIndex
- author_list.List(lc) = aitem$
- Else
- lc = author_list.ListIndex
- author_list.RemoveItem lc
- MsgBox "Information deleted for au_id " & text1(0).Text
- author_list.ListIndex = 0
- End If
- End If
- Else
- Exit Sub
- End If
- author_list.Enabled = True
- chgbut.Visible = True
- updbut.Visible = False
- newrec.Visible = True
- cancelbut.Visible = False
- delbut.Visible = True
- For i = 0 To 8
- text1(i).Enabled = False
- Next
- End Sub
-